'Getting Direct File Links from Dropbox
Is there a way to get "Direct File Links" from Dropbox in android code without using the Dropbox API's?
I searched a lot on this but did not find a solution. Any responses will be appreciated.
Solution 1:[1]
get the file link for exemple https://www.dropbox.com/s/blablabla/test.pdf
replace www by dl
add ?dl=1 to the end
result of our example: https://dl.dropbox.com/s/blablabla/test.pdf?dl=1
Solution 2:[2]
Get the Dropbox link. Something like:
https://www.dropbox.com/s/abcdefg1234567/image.jpg?dl=0
Now replace the part after the ? with raw=1
https://www.dropbox.com/s/abcdefg1234567/image.jpg?raw=1
Paste in a browser and press Enter. That will redirect you to the actual file link. Something like:
https://dl.dropboxusercontent.com/content_link/aBcdEfGHiJ1234567890/file
Be careful to always use the raw=1 link though. The dl.dropboxusercontent.com that you are redirected to has a limited shelf life and will expire.
Solution 3:[3]
You can use the Chooser: https://www.dropbox.com/developers/dropins/chooser/android. It will present UI to the user to let them choose a file, and then it will give your app a URL you can use to download the file, or just the file content itself.
Solution 4:[4]
Get the share link of the file:
https://www.dropbox.com/s/abcdefg1234567/image.jpg?dl=0
At the end, replace dl=0 to dl=1:
https://www.dropbox.com/s/abcdefg1234567/image.jpg?dl=1
Solution 5:[5]
Sometimes the method described in other answers just does not work, and the url pattern is
https://www.dropbox.com/s/<hash>/filename?dl=0
->
https://www.dropbox.com/s/dl/<hash>/filename
Solution 6:[6]
There are many ways to access files stored on Dropbox. You can easily share the file from the dashboard or the desktop app, which yields:
https://www.dropbox.com/s/abcdefghijklmnop/file.txt?dl=0
And the direct download version:
https://www.dropbox.com/s/abcdefghijklmnop/file.txt?dl=1
And the raw DL version:
https://www.dropbox.com/s/abcdefghijklmnop/file.txt?raw=1
But I also discovered a pattern for the raw DL version without the query parameter:
https://www.dropbox.com/s/raw/abcdefghijklmnop/file.txt
And I believe the ID remains the same, eg, in this case abcdefghijklmnop.
Interestingly (likely do to my ignorance using wget), you can also just ask for the file in the terminal with the following URL:
wget https://www.dropbox.com/s/abcdefghijklmnop/file.txt
And this downloads the file just fine.
In a browser, requesting that URL will trigger the Dropbox in-browser file viewer, which contains the response from the request, which is messy when dealing with file downloading programmatically.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MKB |
| Solution 2 | |
| Solution 3 | user94559 |
| Solution 4 | Jayavinoth |
| Solution 5 | jmihalicza |
| Solution 6 | nicorellius |
