cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We want to make our Community work for you and we need your help. Take our short survey!
Close

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: 

Dropbox API to download All Content

Highlighted

Dropbox API to download All Content

Explorer | Level 4

Hi there, I am trying to fetch all content within a certain directory and display its content. The way it's set up now, it can fetch all files, but not directories within this directory. 

dbx
    .filesListFolder({path: '/App'})
    .then(response => {
      for (let i = 0; i < response.entries.length; i++) {
        dbx
        .filesDownload({path: `/App/${response.entries[i].name}`})
        .then(resp => {
          let blob = resp.fileBlob;
          blob.name = response.entries[i].name;
        });
      }

Is there a single API method that can simply fetch all content within a directory?

1 Accepted Solution

Accepted Solutions
Highlighted

Re: Dropbox API to download All Content

Dropboxer
Dropboxer

The only way to download an entire folder at once like that is via filesDownloadZip.

View solution in original post

7 Replies 7
Highlighted

Re: Dropbox API to download All Content

Dropboxer
Dropboxer
There isn't a single method to retrieve everything. The interface is paginated in order to support folders with many items. (Otherwise, calls would start breaking when there are very large lists to return.)

So, in order to retrieve everything, you need to use both filesListFolder and filesListFolderContinue as documented:

https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesListFolder__anchor
https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesListFolderContinue__anchor

Also, if you want nested entries, you can set recursive=true when calling filesListFolder:

https://dropbox.github.io/dropbox-sdk-js/global.html#FilesListFolderArg
Highlighted

Re: Dropbox API to download All Content

Explorer | Level 4

Thanks for the response Greg. As I'm trying it out, I can't seem to get the response I want. Am I not calling the API correctly?

dbx
    .filesListFolder({path: '/App', recursive: true})
    .then(response => {
      console.log(response.entries); // works

      dbx
      .filesListFolderContinue({cursor: response.cursor})
      .then(resp => {
        console.log(resp.entries); // empty array
      });
    })
    .catch(error => console.error(error));
Highlighted

Re: Dropbox API to download All Content

Dropboxer
Dropboxer
You should always check the 'has_more' value for each result (from both filesListFolder and filesListFolderContinue) and call back again to filesListFolderContinue if it's true. There's more information about this in the documentation:

https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesListFolder__anchor

In this version of your code, you're always calling back to filesListFolderContinue once. Since you're not checking 'has_more', that call may be unnecessary (if has_more for filesListFolder is false), or insufficient (if has_more for filesListFolderContinue is true).

Please update your code accordingly and let me know if there are entries that aren't getting returned at all.
Highlighted

Re: Dropbox API to download All Content

Explorer | Level 4

With 'recursive' set to true, I get all the files and 'has_more' is equal to false. So I guess I don't need filesListFolderContinue. Although I'm getting all the files I'm only getting the metadata, I'm still trying to get the fileBlob to be able to retrieve the content within the file. With my original code, I was able to get fileBlob for each file, but it excluded each directory. Is there a way to get the fileBlob for both files and directories?

Highlighted

Re: Dropbox API to download All Content

Dropboxer
Dropboxer
In this case it sounds like everything is on the first page, but note that that's not guaranteed, so you should keep the filesListFolderContinue implementation based on has_more.

To get actual file data, you should use filesDownload as you had in your original code. That doesn't support folders though. To download folders, either iterate through and download each file underneath using filesDownload, or use filesDownloadZip to download a zip of the folder. You would need to then unzip the download, so it may be simpler to just use filesDownload on each nested file.
Highlighted

Re: Dropbox API to download All Content

Explorer | Level 4

Is there no way to download the folder with the files in it instead of just the files?

Highlighted

Re: Dropbox API to download All Content

Dropboxer
Dropboxer

The only way to download an entire folder at once like that is via filesDownloadZip.

View solution in original post

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?