You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

Eridanus's avatar
Eridanus
New member | Level 2
2 months ago

Downloading A file from a shared link using the API

Hello, I've tried downloading an Audio File from a share link using the suggested method on dropbox-sdk-js but I keep getting an error:

 

 

Error downloading file: DropboxResponseError: Response failed with a 401 code

 

 

Here's my code:

 

 

import { Dropbox } from "dropbox"; 


// Inside the component:



      // Download function
  const downloadTrack = () => {
  const ACCESS_TOKEN = process.env.ACCESS_TOKEN
   
  const SHARED_LINK =
      "https://www.dropbox.com/scl/fi/2jqckdrbnq60hr8mq3std/Natamani-Kutembea-Nawe-Teacher-John-CW.mp3?rlkey=1eepmp9jz6wc155inir5hfhl2&st=3c8eq4ed&dl=0";

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

    dbx
      .sharingGetSharedLinkFile({ url: SHARED_LINK })
      .then(function (response) {
        const blob = response.result.fileBlob; 
        const downloadUrl = URL.createObjectURL(blob); 

        const downloadButton = document.createElement("a");
        downloadButton.setAttribute("href", downloadUrl);
        downloadButton.setAttribute("download", response.result.name); 
        downloadButton.setAttribute("class", "button");
        downloadButton.innerText = "Download: " + response.result.name;

        document.getElementById("results").appendChild(downloadButton);
      })
      .catch(function (error) {
        console.error("Error downloading file:", error);
      });

    return false;
  };

 

 

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

    Check the response body for a more specific error message. With the JavaScript SDK, you should be able to by checking the nested `error.error` object.

     

    An error response with a 401 status code like this should indicate an issue with the authorization though; for instance, the access token used may be invalid or expired. Make sure you're using a valid access token.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,884 PostsLatest Activity: 7 hours ago
326 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!