cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Organizing your research is important to easily review and share it. Learn how Kim uses Dropbox to gather and organize her research right 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: 
1
Ask
2
Reply and help

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

Re: Binary to image

Greg-DB
Dropboxer

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);
  });
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?