cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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 size without authenticating?

Get size without authenticating?

Ze'ev G.
New member | Level 1

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

2 Replies 2

Greg-DB
Dropbox 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.)

Ze'ev G.
New member | Level 1

Thanks. That works, however, I had to use "curl -LI", otherwise it tries to download the entire file. And it worked fine with the original "dl=0" link as well.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Ze'ev G. New member | Level 1
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?