You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

mattia o.'s avatar
mattia o.
New member | Level 2
8 years ago

How use /get_thumbails response

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

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff
    The get_thumbails endpoint returns the raw data for the thumbnail itself, and it looks like that's working properly for you.

    What you do with that thumbnail data is up to you. For example, you can save it to a local file on your server and serve it in an img tag. Or, you may be able to convert it to base64 and use it in a data URI for the src for an img tag. Both of those are themselves unrelated to Dropbox itself though, so I'm afraid I can't offer too much insight there.
    • wishfuluser's avatar
      wishfuluser
      Collaborator | Level 8
      Hi Greg—I realize this is not the right way to ask what I'm about to ask, but I'm not sure what else to try...and your posts are the best evidence I can find of Dropboxers engaging on this site.

      A high number of users are experiencing sync challenges because very basic information (file and folder sizes; number of items in folders; etc.) are not surfaced to users in web view. This seems like very very basic stuff that is unavailable and it is causing lots of users' pain points. Inability to see this very basic information makes Selective Sync highly manual at best or essentially impossible at worst.

      This is a very, very old thread with many upvotes and new users joining every week...but it receives no attention because it is in the (perhaps ignored?) feature request area. Would anyone at Dropbox be able to give this some attention?

      https://www.dropboxforum.com/t5/Dropbox/See-folder-size/idc-p/213349#M43590

      Thanks—from wishfuluser and hundreds of others.
      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        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.

         

    • mattia o.'s avatar
      mattia o.
      New member | Level 2

      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&colon;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);

       

    • slolal25's avatar
      slolal25
      New member | Level 2

      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"

       

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,910 PostsLatest Activity: 3 days ago
333 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!