We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

perco's avatar
perco
Explorer | Level 4
5 months ago

Get file content url from dropboxusercontent domain with javascript

Hello,

I'm encountering a problem while trying to obtain the content URL of a file. Specifically, when I use a shared link to fetch a file, I receive a 302 response but i encounter CORS issues. This prevents me from following the redirect to obtain the file's content URL i guess. I don't face this issue when using curl or Python.

Below, the sequence of API calls I'm making. I followed this post :

  • sharingGetSharedLinkMetadata 
  • filesListFolder
  • sharingGetSharedLinkFile 
  • fetchSharedLinkFileUrl (In this step, i'm using fetch and replacing dl=0 with dl=1 in the file url but i'm facing Cors issues)

 

Could you provide any insights or recommendations on how to successfully retrieve the file content URL ? The URL format I'm dealing with is: 
https://*.dl.dropboxusercontent.com/cd/0/get/*/file?dl=1#.

My goal is to load an audio file into a JavaScript audio player. The HTML5 audio player can handle redirects without any issues, libraries like wavesurfer.js cannot, resulting in CORS problems. The only method I've found successful for loading audio files into wavesurfer is by using the direct dropboxusercontent URL. You can see this in action on their playground: https://wavesurfer.xyz/examples/?basic.js.

 

Best regards,

  • Hi perco,

    In cases like yours, an easy workaround would be to replace original share link domain, pointing to your music/song (www.dropbox.com) to dl.dropboxusercontent.com, without changing anything else. 😉 That's it.

    Hope this helps.


  • perco wrote:

    ...

    • sharingGetSharedLinkFile 

    ...


    perco, I want to mention something I skipped before; just for completeness.

    Once you have gotten the file content using the mentioned call, you don't need to use any link at all, so no any CORS issues would take place. You can just use received Blob object to initialize your player. 😉

     

    PS: The discussed CORS issues may be considered as Dropbox links bugs though. Let's hope this will be fixed - it's meaningless response CORS headers to differ based on the request form, I think.

  • Hi perco,

    In cases like yours, an easy workaround would be to replace original share link domain, pointing to your music/song (www.dropbox.com) to dl.dropboxusercontent.com, without changing anything else. 😉 That's it.

    Hope this helps.

    • perco's avatar
      perco
      Explorer | Level 4

      Works like magic.
      Thanks a lot !

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,878 PostsLatest Activity: 9 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!