0

So, I am trying to display an image on my web application. I am getting this image from a Dropbox folder. I want to get a URL I could use to show the image in HTML using the src attribute.

I have written this code:

function downloadFile() {
  var Dropbox = require('dropbox').Dropbox;
  var ACCESS_TOKEN = "XXXXXXXXXXX"; // Here the access token key
  var dbx = new Dropbox({ accessToken: ACCESS_TOKEN });

  dbx.filesDownload({ path: '/desiredImg.jpg' })
    .then(function(response) {
      var results = document.getElementById('results');
      var img = document.createElement('img');
      img.src = window.URL.createObjectURL(response.fileBlob);
      console.log(response);
      console.log(response.fileBlob);
    })
    .catch(function(error) {
      console.error(error);
    });
  return false;
}

Result

I am having this result:

Error

but I am also having this error:

Can anyone help me figure this out?

3
  • [Cross-linking for reference: dropboxforum.com/t5/Discuss-Dropbox-Developer-API/… ]
    – Greg
    Commented May 28, 2021 at 17:11
  • @user29 A bit unrelated to the original question but very important. I think it is not a good idea to use your dropbox api access token in the frontend. It should be used in the backend. Commented Jul 17, 2021 at 19:51
  • @MuhammadKamal thank you for your advice
    – user29
    Commented Oct 29, 2021 at 16:54

1 Answer 1

0

The error was from the img.src = window.URL.createObjectURL(response.fileBlob);
It has to be : img.src=window.URL.createObjectURL(response.result.fileBlob);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.