Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hi, I'm trying to figure out how I should use the response of the /get_thumbnail call.
What I'm actually receiving are some raw data like the following:
�����JFIF���������C� %# , #&')*)-0-(0%()(���C (((((((((((((((((((((((((((((((((((((((((((((((((((����@�0"�������������� �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz����������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�....
Which type of convertion I should apply in order to use it in a <img /> tag?
Thanks for your help
I'm trying the solution below but I'm not be able to display the image, could you please add a js example?
// data represents the response of the /get_thumbnail
var imgsrc='data:image/jpeg;base64,' + btoa(escape(data)); var img = new Image(100, 100); // width, height values are optional params img.src=imgsrc; document.body.appendChild(img);
Hi @wishfuluser, thanks for reaching out, but for future reference, please do not post unrelated replies in threads like this. It makes it more difficult to keep track of the conversation in the thread.
That said, I'm afraid I can't help with the topic you linked to, as that's not my area of expertise. I know that other Dropbox employees do read user feedback like this, even if they don't always respond.
[Cross-linking for reference: https://stackoverflow.com/questions/43026363/convert-dropbox-get-thumbnail-response-to-img ]
Hi @mattia o., it looks like there are some examples of doing this here:
https://stackoverflow.com/questions/20035615/using-raw-image-data-from-ajax-request-for-data-uri
I recommend looking into using the official Dropbox API v2 JavaScript SDK though, as it may make this easier. For example, you could probably then do something like:
dbx.filesGetThumbnail({"path": "/test.jpg"}) .then(function(response) { var img = document.createElement('img'); img.src=window.URL.createObjectURL(response.fileBlob); document.body.appendChild(img); }) .catch(function(error) { console.log("got error:"); console.log(error); });
@wishfuluser Unfortunately I'm afraid I don't have anyone in particular I can direct you to.
It is indeed raw file data! However, in this case it works similarly to opening a JPEG image in notepad and copying it into another empty notepad file and renaming the file extension to JPEG - you may notice that the second file will not display an image and return an error! Depending on what media you are using to copy and paste this binary data, it may store it incorrectly then paste the corrupted data.
I too had this same issue with many question marks showing up in the JFIF content-download returned from get_thumbnail API. I'm curious how it would work with DataURI but I was able to convert the returned JPEG/JFIF into an img tag by first converting it into a "blob" like below AND setting overrideMimeType to the "text/plain"
Below is a Javascript example using XMLHttpRequest that I used in my project:
const Http = new XMLHttpRequest();
const url = 'https://content.dropboxapi.com/2/files/get_thumbnail_v2';
//make sure that all text stays as plain text when read in...
Http.overrideMimeType('text/plain; charset=x-user-defined');
Http.open("POST", url);
Http.responseType = "blob";
Http.setRequestHeader('Authorization', 'Bearer ' + access_token_dropbox);
Http.setRequestHeader('Dropbox-API-Arg', JSON.stringify(data));
Http.send();
Http.onreadystatechange = (e) => {
if (Http.readyState === 4) {
let jpegData = Http.response;
var imageUrl = URL.createObjectURL(Http.response);
document.getElementById("firstDiv").innerHTML = `<img src="${imageUrl}" alt="jo mama" />`;
}}
I got this idea from another question posed here that had a similar issue and was resolved by changing xmlhttprequest.responseType to "blob"
Hi there!
If you need more help you can view your support options (expected response time for a 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!