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.