We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.
Forum Discussion
Ze'ev G.
10 years agoNew member | Level 1
Get size without authenticating?
Can I get the size of a file via a CURL command given only a link without authenticating?
E.g.,
https://www.dropbox.com/s/uf12345szlap449/Files.mp4?dl=0
Greg-DB
10 years agoDropbox Staff
Shared links like this (generally) don't require you to authenticate to access the content, so you can get the content and check the length. For example, using this link:
https://www.dropbox.com/s/vv7us05r9z46lwt/hello_world.txt?dl=0
We can ask for the raw file content by modifying the parameters as shown here:
https://www.dropbox.com/help/201
This gives us this version of the link:
https://www.dropbox.com/s/vv7us05r9z46lwt/hello_world.txt?raw=1
We can then access the content programmatically, e.g., using curl:
curl -L https://www.dropbox.com/s/vv7us05r9z46lwt/hello_world.txt?raw=1
(The -L is necessary to follow redirects.)
The response contains the length in the "Content-Length" header, e.g.:
Content-Length: 14
Alternatively, you can check the length of the returned file yourself.
Or, here's a more advanced method, using the Python requests library, to get the Content-Length without downloading the file, by using a HEAD request:
import requests
url = "https://www.dropbox.com/s/vv7us05r9z46lwt/hello_world.txt?raw=1"
redirected_url = requests.head(url).headers['location']
content_length = requests.head(redirected_url).headers['Content-Length']
print content_length
(Just don't re-use redirected_url. Always get a new one from the original link.)
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,875 PostsLatest Activity: 2 years agoIf 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!