Take Your Search Game to the Next Level with Dropbox Dash  🚀✨ Curious how it works? Ask us here! 

Forum Discussion

vildantursic's avatar
vildantursic
Explorer | Level 4
8 years ago

Binary to image

 

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

 

Any kind of solution would be nice :D thank you!

1 Reply

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago

    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);
      });

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,011 PostsLatest Activity: 3 hours ago
392 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!