cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Iterating and Downloading from shared link subfolders

Iterating and Downloading from shared link subfolders

avieini
New member | Level 2

Hi all,

I have a shared link looking like this: https://www.dropbox.com/sh/o0qb...

In this link I have folders and subfolder and some heavy files in them. 

I searched across the web and didn't find anything that could help me.

I basically want to be able to iterate over the folders and the subfolders and download files from specific subfolders. 

I am working with Python and the best I could do so far was retrieve the subfolders names and id's (by using this theard )

Do you have any idea how to tackle it?

Thanks!

4 Replies 4

Pikamander2
Super User

Here's the HTTP documentation and here's the Python documentation (see the dropbox.dropbox subpage).

For HTTP requests, the /download, /get_shared_link_file, and /list_folders endpoints sound like they would be helpful.

For the Python library, check out the files_downloadfiles_download_to_file, and files_list_folder functions.

The dropbox API is very complex, so you'll need to read through the documentation to see what all is available.

Greg-DB
Dropbox Staff

@avieini Yes, as Pikamander2 mentioned, there are some methods that can help with this, like files_list_folder from the thread you linked to, as well as sharing_get_shared_link_file.

Here's a basic example of what using those may look like:

import dropbox

ACCESS_TOKEN = "..."
url = "https://www.dropbox.com/sh/..."

dbx = dropbox.Dropbox(ACCESS_TOKEN)

shared_link = dropbox.files.SharedLink(url=url)
print(dbx.files_list_folder(path="", shared_link=shared_link))

filename = "..."
print(dbx.sharing_get_shared_link_file(url=url, path=filename))

avieini
New member | Level 2

Hi Greg, thanks for your answer

The point that I get confused with is how do I (iteratively) acess the subfolders of the main folder ? 

The files_list_folder method only gives me the names and the ids of those subfolders.

If I could "enter" each subfolder I would be able to downlaod it's files.

Hope now it's clearer.

Greg-DB
Dropbox Staff

@avieini While the 'files_list_folder' method does not support the native 'recursive' mode when listing from a shared link, you can iteratively list out the contents of the subfolders, by calling again with the relevant 'path' value(s). For example, say if I make the first call:

print(dbx.files_list_folder(path="", shared_link=shared_link))

If that shows me that there is a subfolder with a 'name' of 'another folder', for example, I can then call again to list that one, like:

print(dbx.files_list_folder(path="/another folder", shared_link=shared_link))

That will give the listing for that subfolder, and then likewise I can call 'sharing_get_shared_link_file' to download a file from inside that subfolder, like:

print(dbx.sharing_get_shared_link_file(url=url, path="/another folder/test.txt"))
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    avieini New member | Level 2
  • User avatar
    Pikamander2 Super User
What do Dropbox user levels mean?