User-Agent affects Dropbox shared links download User-Agent affects Dropbox shared links download curl curl

User-Agent affects Dropbox shared links download


Dropbox may offer the raw file content via a redirect like this for some User-Agents, e.g., for curl where it's unlikely the user wants the HTML of the preview page. This isn't documented or guaranteed though, so I wouldn't recommend relying on it.

There are some documented URL parameters you can use to manage the behavior of shared links though:

https://www.dropbox.com/help/201


I ran into the same problem trying to pull a file from Dropbox using Java. It worked perfectly for curl, but failed for Java (the HTML page was returned instead). Setting the User-Agent header in my Java app to curl/7.54.0 worked, but that seemed like an awful hack.

The link in Greg's answer pointed me to the solution:

To force a browser to download the contents of a link rather than display it, you can use dl=1 as a query parameter in your URL. For example:

https://www.dropbox.com/s/a1b2c3d4ef5gh6/example.docx?dl=1

So I replaced the dl=0 in the URL with dl=1, and everything works perfectly -- no need to change the User-Agent header. There are still 301 and 302 redirects to follow, but that's not a problem for java.net.HttpURLConnection and most other libraries.