Uploading file through Fetch


I am trying to get an image from currently selected Artboard and upload it to a server. I am able to get base64 image but trying to convert it to a File so that it can be uploaded is not working.

Here is code for turning base64 to a blob. I never receive blob.

function b64toBlob(b64Data, contentType, sliceSize) {
  contentType = contentType || ''
  sliceSize = sliceSize || 512

  var byteCharacters = atob(b64Data)
  var byteArrays = []

  for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
    var slice = byteCharacters.slice(offset, offset + sliceSize)

    var byteNumbers = new Array(slice.length)
    for (var i = 0; i < slice.length; i++) {
      byteNumbers[i] = slice.charCodeAt(i)

    var byteArray = new Uint8Array(byteNumbers)

  var blob = await new Blob(byteArrays, { type: contentType })
  return blob


Console logging byteArrays and content type all works.

new Blob(byteArrays, { type: contentType }) seems to be the issue. And there are also no errors.


Blobs aren’t currently supported by our fetch implementation. Instead, you’ll need to upload an ArrayBuffer. However that does mean changes on your backend to support the request.

Blob and FormData support are coming soon, though.


How do I grab ArrayBuffer from the base64 image? Would it be the atob() function?


So you’ve got an ArrayBuffer with byteArrays – you should be able to send that with fetch directly.