cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know more about how you can find anything and protect everything? Check it out here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get file content url from dropboxusercontent domain with javascript

Get file content url from dropboxusercontent domain with javascript

perco
Explorer | Level 4

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,

1 Accepted Solution

Accepted Solutions

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.

View solution in original post

3 Replies 3

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
Explorer | Level 4

Works like magic.
Thanks a lot !


@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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    perco Explorer | Level 4
What do Dropbox user levels mean?