Forum Discussion

Fabito's avatar
Fabito
Explorer | Level 4
7 years ago

Download files from Dropbox using SDK Javascript

Hi, all

 

I'm trying download files from my Dropbox using SDK Javascript, but I can't. I'm calling this code from my button html, but nothing happen. Don't show error message or something. I readed about the "filesDownload" documentation and apparently is the same code for upload files (that I founded to upload files with SDK Javascript)

 

This is my code

 

function downloadFile() {
      var ACCESS_TOKEN = ""; // Here the access token key
      var dbx = new Dropbox({ accessToken: ACCESS_TOKEN });
      
   
    dbx.filesDownload({ path: '/5. Productos de las LGAC/Estudiantes/Generación 2018-2020/Artículos/Ricardo-Derechos.pdf'})
        .then(function(response){
          var results = document.getElementById('results');
          results.appendChild(document.createTextNode('File Downloaded!'));
          console.log(response);
        })
        .catch(function (error) {
        console.error(error);
    });
    return false;
}

If somebody can help me to find out the problem, will be very appreciated

 

Regards

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    What version of the JavaScript SDK are you using? If you're using the latest version, you should get this error:

    Uncaught TypeError: Dropbox is not a constructor

    from this line:

    var dbx = new Dropbox({ accessToken: ACCESS_TOKEN });

    If you're not using the latest version, please do upgrade and switch to using this constructor:

    var dbx = new Dropbox.Dropbox({ accessToken: ACCESS_TOKEN });

    Let me know if that doesn't help.

    • Fabito's avatar
      Fabito
      Explorer | Level 4

      Hi again.

       

      The version that I was using is 4.1.1. After your message I tried change it and use this: 

      <script src="https://unpkg.com/dropbox/dist/Dropbox-sdk.min.js"></script>

       Also I wrote the code suggested

       

      var dbx = new Dropbox.Dropbox({ accessToken: ACCESS_TOKEN });

       But nothing happen. I push the button and only the page is refreshed. Thanks for the help

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff
        This code is working for me. Do you get any error or output in the console?

        Can you provide a more complete sample page for this issue? It sounds like you may have the button hooked up to a different event, e.g., submitting a form, or something to that effect, causing the refresh.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,950 PostsLatest Activity: 45 minutes ago
352 Following

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

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!