Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Bitbucket API commit image and base64 encoding


I'm using nodejs to push up an image to a repo from the src endpoint using multipart/form post and no matter how I send it, binary, text, raw it's always unusable after upload.  What is the proper way to upload an image from node?  I have successfully pushed plain text files but not images/binary data.  I am using the npm FileReader package to read the file contents and I've tried


 but nothing seems to work.  I'm using the npm package "form-data" to do the form post which works fine for regular text files.

Also is base64 encoding supported?  It doesn't appear to be supported because the api doesn't decode the file after upload and I can't send the "Content-Transfer-Encoding": "base64" header because it's not allowed from the CORS pre-flight request.  Seems like base64 encoding is important for multipart form posts of binary data.

Any help appreciated!

3 answers

1 accepted

0 votes
Answer accepted

In case anybody is looking for this here is the function we needed to make our uploaded binary files work, thanks to @taussoe for the snippet!

Check out netlify cms for the implementation soon.

dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
var byteString = atob(dataURI.split(',')[1]);

// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]

// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);

// create a view into the buffer
var ia = new Uint8Array(ab);

// set the bytes of the buffer to the correct values
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);

// write the ArrayBuffer to a blob, and you're done
var blob = new Blob([ab], {type: mimeString});
return blob;





Hi @zanedev  any luck yet with commiting image to Bitbucket via api?

Crickets :)  Anybody have any ideas here?  Anybody uploading binary data using node/javascript to the bitbucket api?

Aaaaaand a one. I am! At least, now I found how to convert the damn images to blobs! Thank you Zane!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,256 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you