25

I'm building an application to automatically trigger a download of a Dropbox file shared with a user (shared file/folder link). This was straight forward to implement for Dropbox links to files, as is outlined here.

Unfortunately this doesn't work for shared folders. Anyone have suggestions on how I could

  • Download the all of it's contents (maybe get a list of the files links inside it to download?)
  • or
  • Download a zip of the folder

Currently I can go to the url and do some screen-scraping to try and get the contents list, but the advantage of the solution described in the linked Dropbox blog entry for files is that no scraping is needed, so it's much more reliable and efficient.

2
  • Standard FTP libraries don't work in this situation, something like paramiko? Commented Nov 26, 2013 at 20:34
  • This is for Dropbox shared links only. Updated the first line to make that clearer.
    – Cian
    Commented Nov 26, 2013 at 20:46

3 Answers 3

30

Dropbox's support team just filled me in on the best way to do this:

Just add ?dl=1 to the end of the shared link. That'll give you a zipped version of the shared folder.

So if the link shared with a user is https://www.dropbox.com/sh/xyz/xyz-YZ (or similar, which links to a shared folder), to download a zipped version of that folder just access https://www.dropbox.com/sh/xyz/xyz-YZ?dl=1

Hope this helps someone else also.

7
  • 2
    Doesn't seem to work with folders larger than 2 Gb though - the resulting file is corrupt.
    – DenNukem
    Commented Jul 28, 2014 at 5:06
  • 2
    actually, as of now you'll get a 500 error if the resulting size is over 1GB
    – xaphod
    Commented Sep 15, 2015 at 18:13
  • How to know the share url if change the folder name? Maybe can encrypt it somehow using the access_token? @Cian
    – Mr. Blond
    Commented Oct 25, 2015 at 16:13
  • @EdgarsŠturms I'm not sure - I think you'd need to request the share URL again. This way of downloading assumes you have the correct share URL.
    – Cian
    Commented Nov 20, 2015 at 11:04
  • @Cian Found the answer to my question stackoverflow.com
    – Mr. Blond
    Commented Nov 21, 2015 at 20:31
6

When downloading direct shared links to files through python I was getting html pages instead of actual file content. Changing ?dl=1 wasn't helping. I then noticed that wget was downloading the actual file, even when ?dl=0. Seems like dropbox detects wget user agent and responds with the file, so setting the user agent header to Wget/1.16 (linux-gnu) in python solved the issue, now any dropbox shared link is being downloaded properly:

headers = {'user-agent': 'Wget/1.16 (linux-gnu)'}
r = requests.get(url, stream=True, headers=headers)
with open(filepath, 'wb') as f:
    for chunk in r.iter_content(chunk_size=1024): 
        if chunk:
            f.write(chunk)
-4

This should really be done by using the awesome Dropbox Core API, which allows you to upload or download files, see information on file deltas and information on shared folders/files.

The API is rather simple, as it returns a common URL to download any item from Dropbox accounts with.

3
  • 1
    How could this be done through the Core API? The issue is downloading folders from a link sent to a user. Doing this through the Dropbox Core API would require Oauth access to the account of every person who sent files to the user?
    – Cian
    Commented Nov 27, 2013 at 9:23
  • 1
    Yes, it would require each user to allow your application to login on their behalf, however, your application would have access to everything more directly. Otherwise, you haven't explained your problem well enough to get a different answer.
    – VooDooNOFX
    Commented Nov 27, 2013 at 10:19
  • 1
    The link to the Dropbox blog regarding downloading files from links illustrates the situation exactly in Dropbox's words - but the problem is providing the same functionality for folders, as desciribed in the question.
    – Cian
    Commented Nov 27, 2013 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.