Programmatically download content from share links

Posted by Steve Marx on August 20, 2013

A “Dropbox share link” is a link that’s intended to be sent out to another Dropbox user. The URL looks like this picture of me doing my job as a developer advocate: https://www.dropbox.com/s/r3p1au45g3rylvs/advocated.jpeg.

A share link renders a preview of the content and offers options for the user to download or view the actual file. Share links can be created from the Dropbox UI (right-click and select “Share Dropbox Link”), or they can be created using the Core API, Sync API, or the Chooser.

If you have a share link for a file, you can download the file directly by changing the domain from www.dropbox.com to dl.dropboxusercontent.com. For example, here again is me advocating: https://dl.dropboxusercontent.com/s/r3p1au45g3rylvs/advocated.jpeg.

If you just need to download the file once, it’s probably better to use a media link (“direct link” in Chooser terminology), but those links expire after four hours. Converting a share link is useful if you need a more “permanent” download link. I put “permanent” in quotes because a user can unshare the file at any time or simply move or delete it, at which point the link will stop working.

Examples

You can convert the “preview link” returned by the Chooser into a downloadable link in JavaScript:

function chooserSuccess(event) {
    var previewLink = event.files[0].link;
    var downloadableLink = previewLink.replace(
        'www.dropbox.com', 'dl.dropboxusercontent.com');
}

If you get a share link using the Python Core API SDK, you can do a similar conversion:

shareLink = DropboxClient(token).share(path)
downloadableLink = shareLink.replace('www.dropbox.com', 'dl.dropboxusercontent.com', 1)