You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

philip-lf's avatar
philip-lf
Explorer | Level 4
7 years ago

Dropbox API to download All Content

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?

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff
    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
    • philip-lf's avatar
      philip-lf
      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));
      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff
        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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,882 PostsLatest Activity: 3 hours ago
325 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!