cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Binary to image

Binary to image

vildantursic
Explorer | Level 4

 

filesDownload or filesGetThumbnail returns object with fileBinary property. I can't in any way I tried convert that data to image.

Most of the time I get this exception

DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.

Unless I do this

...
img.src='data:image/jpeg;base64,' + window.btoa(unescape(encodeURIComponent(response.data.fileBinary)));
...

But again it is unreadable

And here is screenshot of original fileBinary data and converted data with code above

Screenshot from 2018-02-11 00.15.13.png

 

Any kind of solution would be nice 😄 thank you!

1 Reply 1

Greg-DB
Dropbox Staff

I believe you can just do something like this instead:

 

dbx.filesDownload({path: '/test.jpg'})
  .then(function(response) {
    var fileUrl = URL.createObjectURL(response.fileBlob);
    var img = document.createElement('img');
    img.setAttribute('src', fileUrl);
    document.getElementById('results').appendChild(img);
  })
  .catch(function(error) {
    console.error(error);
  });
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?