Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Download Content from Shared Dropbox Folder Links

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.

like image 467
Cian Avatar asked Nov 26 '13 20:11

Cian


People also ask

Can you download from Dropbox shared link?

You can make simple modifications to Dropbox links to share files the way you want. You can append the link URL to force the content to download or render in your browser.

How do I create a direct download link in Dropbox?

Go to Dropbox.com, find your file, and click the Copy link button that appears when you hover over it. Or, on your desktop, right-click on the file, and select Copy Dropbox Link. Copy that link and paste it in your browser, and it should download the file directly.

How do I download a shared link?

In the upper right corner of the Share Settings dialog box, there's a button that reads “Get shareable link.” Click that. Once that option is enabled, the link will be populated. You can simply highly it, then copy and paste it into an email, chat message, or anywhere else.


2 Answers

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.

like image 123
Cian Avatar answered Nov 03 '22 04:11

Cian


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)
like image 23
serg Avatar answered Nov 03 '22 04:11

serg