Forum Discussion

bbijals's avatar
bbijals
Explorer | Level 4
8 years ago
Solved

Download file from Dropbox

I have a Chrome based app developed in AngularJS. We wanted to provide dropbox functionalities within the app. I am looking to download files uploaded to dropbox from this chrome app.  I have tried t...
  • chirstius's avatar
    8 years ago

    Hello bbijals, might I first suggest giving the Dropbox Javascript SDK a look as I think it will simplify much of the boilerplate code required when submitted with xhr's.

     

    One way to directly download a file via the SDK might be as follows:

     

    dbx = new Dropbox.Dropbox({ accessToken: TOKEN });
    dbx.filesGetTemporaryLink({path: PATH_TO_FILE}) .then(function(response) { var link = document.createElement("a"); link.href = response.link; document.body.appendChild(link); link.click(); document.body.removeChild(link); delete link; }) .catch(function(error) {
    // handle error console.log(error); });

    This code gets a temporary link to a given file, it then creates a hidden hyperlink pointing to the newly created link, clicks it on behalf of the user, and then cleans it up.

    You can use code like this in a handler to trigger a direct download via the native OS file save dialog.

    Hope that helps!

     

    -Chuck

     

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

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!