0

I am trying to use DropBox API to get a thumbnail from DropBox and show them on Lightning Web Component in Salesforce, but can not do it because in a response Apex receiving body with black rhombs and question marks inside.

I use standard HTTP method to call

    HttpRequest req = new HttpRequest();
        req.setHeader('Authorization', 'Bearer sl.validToken');
        req.setHeader('Dropbox-API-Arg', '{"resource": {".tag": "path","path": "/folderName/pictureName.jpg"},"format": "jpeg","size": "w64h64","mode": "strict"}');
        req.setHeader('Content-Type', 'text/plain; charset=utf-8');
req.setEndpoint('https://content.dropboxapi.com/2/files/get_thumbnail_v2');
        req.setMethod('POST');
        Http httpreq = new Http();
        HttpResponse res = httpreq.send(req);

this is what I receive in body of response in Apex. The same response I have in Postman. https://i.stack.imgur.com/90yjI.png

This is what I have in DropBox explorer with same values and headers (JSON) https://i.stack.imgur.com/ytDxv.png

File scope is Read to everyone. SF Remote Site Settings & CSP Trusted Sites are set.

Short update: I`ve been able to get JSON From header. I did use that piece of code:

List<String> headers = new List<String>(res.getHeaderKeys());
        for(String key : headers){
            System.debug('key ->>> '+key+' = '+res.getHeader(key));
        }
        String jsonString = res.getHeader('Dropbox-Api-Result');
        System.debug('->>>ddd '+jsonString);

But still do not understand how to use it as a thumbnail in LWC.

Thank you in advance for your help.

1 Answers1

0

The /2/files/get_thumbnail_v2 Dropbox API endpoint is a "content-download" style endpoint, meaning the "response body contains file content, so the result will appear as JSON in the Dropbox-API-Result response header". So, the illegible value you're receiving is the actual bytes of the thumbnail data itself. You're currently attempting to display it as text, but you'll instead need to save and display it as an image to see the thumbnail. Refer to your platform's documentation for information on how to display an image.

For reference, the Dropbox API v2 Explorer is built with knowledge of the different endpoint formats, so in this case it displays the metadata from the Dropbox-API-Result response header, and just offers the file data, in this case the thumbnail data, as a download via a "Download" button.

Greg
  • 16,359
  • 2
  • 34
  • 44