Your workflow is unique 👨‍💻 -  tell us how you use Dropbox here.

Forum Discussion

Santhosh T.'s avatar
Santhosh T.
New member | Level 1
9 years ago

Get thumbnail method: Is there a difference in the response generated between v1 and v2 of the API

I have been using Dropbox v1 API to access user images. I use them in my Parse.com cloud code (very similar to node.js). Code below for v1:

}).then(function(dropboxToken){
    return Parse.Cloud.httpRequest(
    {
          method: 'GET',
          url: 'https://content.dropboxapi.com/1/thumbnails/auto' + <path>,
          headers: {
                'Authorization': 'Bearer ' + dropboxToken.get("accessToken")
          }
     });
}).then(function(thumbnail){
     var imageBuffer = thumbnail.buffer;
     var image = imageBuffer.toString('base64');
     response.success(image);
}, function(error){
     response.error(error.message);
});

The above code worked fine. But now I am updating my cloud code to v2 of Dropbox API. Code below:

}).then(function(oauthToken){
     return Parse.Cloud.httpRequest({
            method: 'POST',
            url: 'https://content.dropboxapi.com/2/files/get_thumbnail',
            headers: {
                 'Authorization': 'Bearer ' + oauthToken.get("accessToken"),
                 'Dropbox-API-Arg': JSON.stringify({"path": dropboxFileId})
            }
     });

}).then(function(imageResponse){

     var imageBuffer = thumbnail.buffer;
     var image = imageBuffer.toString('base64');
     response.success(image);

      }, function(error){

             response.error(error.text);
      });

});

For some reason, the v2 code does not work. I do get a response from the server which I have provided in the below Stackoverflow link:

http://stackoverflow.com/questions/36027091/convert-raw-image-data-to-base64-encoded-string

But I somehow do not get the right base64 string. Is there a difference in the responses provided by v1 to v2 of the API? If yes, how do I resolve this issue.

Thanks.

4 Replies

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    9 years ago

    No, both the API v1 and API v2 thumbnail endpoints just return the raw content directly. I just tried this against the HTTP endpoints directly and I got the same exact response body back for both.

  • Santhosh T.'s avatar
    Santhosh T.
    New member | Level 1
    9 years ago

    Thanks Gregory, but I get two different responses:

    Response with v2: 

    { status: 200,

      headers:

       { server: 'nginx',

         date: 'Wed, 16 Mar 2016 21:39:26 GMT',

         'content-type': 'application/octet-stream',

         'content-length': '1731',

         connection: 'close',

         'accept-ranges': 'bytes',

         pragma: 'no-cache',

         'cache-control': 'no-cache',

         'original-content-length': '1731',

         'dropbox-api-result': '{"name": "Logo.jpg", "path_lower": "/logo.jpg", "path_display": "/Logo.jpg", "id": "id:HIY5vU6bHgAAAAAAAAAAAQ", "client_modified": "2015-10-20T03:11:50Z", "server_modified": "2016-02-13T06:08:14Z", "rev": "2a143d0c726", "size": 17150, "media_info": {".tag": "metadata", "metadata": {".tag": "photo", "dimensions": {"height": 157, "width": 225}, "time_taken": "2015-10-20T14:10:53Z"}}}',

         'x-server-response-time': '195',

         'x-dropbox-request-id': '702fa93503a7e87f5d1f46f63e146a21',

         'x-robots-tag': 'noindex, nofollow, noimageindex' },

      buffer: <Buffer ef bf bd ef bf bd ef bf bd ef bf bd 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ef bf bd ef bf bd 00 43 00 06 04 05 06 05 04 06 06 05 06 07 07 06 ... >,

      cookies: undefined,

      text: '\u0000\u0010JFIF\u0000\u0001\u0001\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0000C\u0000\u0006\u0004\u0005\u0006\u0005\u0004\u0006\u0006\u0005\u0006\u0007\u0007\u0006\b\n\u0010\n\n\t\t\n\u0014\u000e\u000f\f\u0010\u0017\u0014\u0018\u0018\u0017\u0014\u0016\u0016\u001a\u001d%\u001f\u001a\u001b#\u001c\u0016\u0016 , #&\')*)\u0019\u001f-0-(0%()(\u0000C\u0001\u0007\u0007\u0007\n\b\n\u0013\n\n\u0013(\u001a\u0016\u001a((((((((((((((((((((((((((((((((((((((((((((((((((\u0000\u0011\b\u0000-\u0000@\u0003\u0001"\u0000\u0002\u0011\u0001\u0003\u0011\u0001\u0000\u001f\u0000\u0000\u0001\u0005\u0001\u0001\u0001\u0001\u0001\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\u0000\u0010\u0000\u0002\u0001\u0003\u0003\u0002\u0004\u0003\u0005\u0005\u0004\u0004\u0000\u0000\u0001}\u0001\u0002\u0003\u0000\u0004\u0011\u0005\u0012!1A\u0006\u0013Qa\u0007"q\u00142\b#B\u0015R$3br\t\n\u0016\u0017\u0018\u0019\u001a%&\'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz\u0000\u001f\u0001\u0000\u0003\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\u0000\u0011\u0000\u0002\u0001\u0002\u0004\u0004\u0003\u0004\u0007\u0005\u0004\u0004\u0000\u0001\u0002w\u0000\u0001\u0002\u0003\u0011\u0004\u0005!1\u0006\u0012AQ\u0007aq\u0013"2\b\u0014B\t#3R\u0015br\n\u0016$4%\u0017\u0018\u0019\u001a&\'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz\u0000\f\u0003\u0001\u0000\u0002\u0011\u0003\u0011\u0000?\u0000*\u001b{fn\'&øR\\8\u0007@\u0013W|DŮ?d}ޕ\u0011`\u00032Xee\u000f8 8A㟈W\u001a$\u0016\u000f\u000fx\u000b\u001a72\r@#\u0019PU,v\u0011hH\u001b\u000e\u0002\\\u0005\u0003o\u0000~"\\%񔖇\u0002O%\u0013fs<\u0001TX=\u000f$G82vy\u0003o\u0004+m>\u001cy\u001cm\u000616-\u0018\'cs7\u0019ۏl{P<!Xj\u001e\u0013^\u0015It\u0003f\'~I\u001d:\u0010(\u0003+c^\nӮ|Sm5K\b\u000e@;GL+\u0002\u00174\u0017/\rx\u000eY\\\u0013K,yC\u000fdu\fz\u0005@1Ӯx\u0000\u0006.\u0019;$lI¶w=GN6h\u0002C4u/\bLĖHXJ\\ʹ\u001f19\'WZ\'؛:Ֆ`pýؖ!W\'$\u0002\u0007}\u0005x╶rF\'\u001a\u000bWM[.X\u00002U3ڽÝWZEŅڮdR\u0019W3Pmb\f\u0000(\u00033}zSk^]ݸ\u000339z96-<SivJ-\u001eh̙NNpIG\u0019O\u001e/-\u0001m\u000fb6V>cg \u000e\u0015\u001f\u000e2\u0010}]Lc\u0011[\u0000\u0002x\u0004\u00015X۵qvcS2Fە_\u001f0\u0004\u0000皳E\u0014\u0001R8/\'\u0010H~э?|e .\u0006B\u001e3V?\u001cW\u0000eS&݋\u0012p0Y\u0004jqw\u0001"8\r؂\u0000[2\u0014W\'\u0003Zj&o0ā3?\u0003@\u001c=\u0004-=joo5($2\tH;v\u0000NpFy8i>:/M\u001e-\u0012g\u001f̌qt\u0007}3ZMte!\\\u000b:t:h\u001e7?Ƞ\u000e"ǚϑqqhmZ\u001c\u0019\u0002q\u001e;Xu\u0014V6.&v";y\u0000\u00024#mnj\u0007v#\u001b2\teIn\u0014sF}SV;\u0004\b[c,u\u0018@\u001c? n.4-b\u001bV%Df\nr\u0000n\u0019?0\u001di6Q\u000f\u0002lc\u001b{ctx\u0012ͽ21偼`{Trn6\u000f.X\u0001?*\u0000' }

     

    and for v1, I get:

    {"uuid":"99952763-ebbc-444d-0860-50ab433959cf","status":200,"headers":{"Connection":"keep-alive","Content-Length":"1731","Content-Type":"image/jpeg","Date":"Wed, 16 Mar 2016 21:10:51 GMT","Server":"nginx","X-Robots-Tag":"noindex, nofollow, noimageindex","X-Server-Response-Time":"206","cache-control":"no-cache","pragma":"no-cache","x-dropbox-metadata":"{\"rev\": \"5737ee9e71\", \"thumb_exists\": true, \"photo_info\": {\"lat_long\": null, \"time_taken\": \"Tue, 20 Oct 2015 14:10:53 +0000\", \"image_dimensions\": [225, 157]}, \"path\": \"/TestParse/Logo.jpg\", \"is_dir\": false, \"client_mtime\": \"Tue, 20 Oct 2015 03:11:50 +0000\", \"icon\": \"page_white_picture\", \"read_only\": false, \"modifier\": null, \"bytes\": 17150, \"modified\": \"Tue, 20 Oct 2015 03:12:07 +0000\", \"size\": \"16.7 KB\", \"root\": \"dropbox\", \"mime_type\": \"image/jpeg\", \"revision\": 87}","x-dropbox-request-id":"db555834aa280849a9ff7ce66bcfcd31","x-dropbox-thumbcachehit":"1"},"text":"\u0000\... (truncated)

    "buffer":{"0":255,"1":216,"10":0,"100":19,"101":10,"102":10,"103":19,"104":40,"105":26,"106":22,"107":26,"108":40,"109":40,"11":1,"110":40,"111":40,"112":40,"113":40,"114":40,"115":40,"116":40,"117":40,"118":40,"119":40,"12":1,"120":40,"121":40,"122":40,"123":40,"124":40,"125":40,"126":40,"127":40,"128":40,"129":40,"13":0,"130":40,"131":40,"132":40,"133":40,"134":40,"135":40,"136":40,"137":40,"138":40,"139":40,"14":0,"140":40,"141":40,"142":40,"143":40,"144":40,"145":40,"146":40,"147":40,"14... (truncated)

     

    As noted before, I used the buffer values to convert my responses to base64. Now since the buffer values are different, I am struggling to get the right base64 string. Can you please let me know how I would get the base64 string from the buffer values which are now in hexadecimal?

    Or is it possible to get base64 from the text body? If yes, how?

    Many Thanks.

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

    The Content-Type header is reporting differently, but the bodies themselves are the same, so it sounds like the issue may be with the library or processing you're doing. I can't offer much help there as we didn't write that though. Maybe the library you're using is changing the response it gives you different based on the Content-Type? In any case, the API doesn't offer an option for changing the format returned by the API call itself.

About Dropbox API Support and Feedback

Node avatar for Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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, Facebook or Instagram.

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!