Announcements
Can you spare 5 minutes to help us improve our online support experience? Get involved!

Retrieve all files in App shared folder (respecting folder tree)

Explorer | Level 4

Hi!

I'd like to display all files of from a shared folder, using DropBox API respecting my folder hierachy. I followed 2 different ways :

1) My first idea was to use the files/list_folder endpoint (and recursive parameter as true) then files/list_folder/continue as mentionned in lot of answers here to get all files and folders.

It works quite nice, but I get all files and folders regardless of the folders tree. And was not able to recreate the initial folder hierarchy by myself cause file doesn't contain his parent folder id.

2) Second idea. Get the list of the first level of folders using files/list_folder, then for each folder found, request the files/list_folder endpoint again to get the list of folder files.

It works but it takes lot of time... I have got 15 folders and the all 16 requests (the root one and one for each folder) takes at least 6s !! (I use guzzle and PHP)

There is a way to know the id of direct parent folder ? (case 1)
Or a better way to retrieve files with better performance ? (case 2)

Thanks.

1 Accepted solution

Accepted Solutions

Re: Retrieve all files in App shared folder (respecting folder tree)

Dropboxer

Hi! Happy to help. A couple clarifying questions:

- Could you clarify what you mean by 'respecting folder heirarchy'? 
- What is the final way you want your files displayed?

In general, your #1 solution is the better way to go. I reccommend continuing to iterate on that solution. 

A response from a successful list_folder response will typically look like this: 

{
    "entries": [
        {
            ".tag": "file",
            "name": "Prime_Numbers.txt",
            "id": "id:a4ayc_80_OEAAAAAAAAAXw",
            "client_modified": "2015-05-12T15:5smiling face with halo8Z",
            "server_modified": "2015-05-12T15:5smiling face with halo8Z",
            "rev": "a1c10ce0dd78",
            "size": 7212,
            "path_lower": "/homework/math/prime_numbers.txt",
            "path_display": "/Homework/math/Prime_Numbers.txt",
            "sharing_info": {
                "read_only": true,
                "parent_shared_folder_id": "84528192421",
                "modified_by": "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc"
            },
            "is_downloadable": true,
            "property_groups": [
                {
                    "template_id": "ptid:1a5n2i6d3OYEAAAAAAAAAYa",
                    "fields": [
                        {
                            "name": "Security Policy",
                            "value": "Confidential"
                        }
                    ]
                }
            ],
            "has_explicit_shared_members": false,
            "content_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
        },
// other entries
];

The property named 'path_lower' (or path_display) contains the explicit path to your file. Those strings contain all the information about where your file lives in relation to your folder heirarchy.

You can either parse the string manually (using a built-in method like `split('/')`) or bring in a module to help work with the path. In both cases you should be able to use the path information to handle your files according to that heirarchy. 

Reply
Loading...
4 Replies

Re: Retrieve all files in App shared folder (respecting folder tree)

Dropboxer

Hi! Happy to help. A couple clarifying questions:

- Could you clarify what you mean by 'respecting folder heirarchy'? 
- What is the final way you want your files displayed?

In general, your #1 solution is the better way to go. I reccommend continuing to iterate on that solution. 

A response from a successful list_folder response will typically look like this: 

{
    "entries": [
        {
            ".tag": "file",
            "name": "Prime_Numbers.txt",
            "id": "id:a4ayc_80_OEAAAAAAAAAXw",
            "client_modified": "2015-05-12T15:5smiling face with halo8Z",
            "server_modified": "2015-05-12T15:5smiling face with halo8Z",
            "rev": "a1c10ce0dd78",
            "size": 7212,
            "path_lower": "/homework/math/prime_numbers.txt",
            "path_display": "/Homework/math/Prime_Numbers.txt",
            "sharing_info": {
                "read_only": true,
                "parent_shared_folder_id": "84528192421",
                "modified_by": "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc"
            },
            "is_downloadable": true,
            "property_groups": [
                {
                    "template_id": "ptid:1a5n2i6d3OYEAAAAAAAAAYa",
                    "fields": [
                        {
                            "name": "Security Policy",
                            "value": "Confidential"
                        }
                    ]
                }
            ],
            "has_explicit_shared_members": false,
            "content_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
        },
// other entries
];

The property named 'path_lower' (or path_display) contains the explicit path to your file. Those strings contain all the information about where your file lives in relation to your folder heirarchy.

You can either parse the string manually (using a built-in method like `split('/')`) or bring in a module to help work with the path. In both cases you should be able to use the path information to handle your files according to that heirarchy. 

Reply
Loading...

Re: Retrieve all files in App shared folder (respecting folder tree)

Explorer | Level 4

Hi! Thanks for the help!

You definitely right. Split the 'path_lower' will do the job to recreate the folder hierarchy.

By 'respecting folder hierarchy' I don't know how to explain ^^ but I'd like to display something like : 

Thank you very much for your quick reply!

Reply
Loading...

Re: Retrieve all files in App shared folder (respecting folder tree)

Dropboxer

Thanks for following up and clarifying! I'm glad Taylor was able to help. Yes, to reconstruct the folder hiearachy like that, you'll want to split the path on "/".

For reference, whenever you're going to display the path to the user, you should use the "path_display" value. Whenever you're using the path to make another API call though, it's best to use the "path_lower" value.

Reply
Loading...

Re: Retrieve all files in App shared folder (respecting folder tree)

Explorer | Level 4

Thanks Greg K. for that clarification. That makes sense for me using "path_lower" to request the API if needed. But good to know.

Reply
Loading...
API Support

Have a question? Our Dropbox Community is here to help you find an answer!
You won’t have to wait too long for a reply, but why not learn more about the Community while you’re here.

Not the right discussion for you? Find out what else our Community has to say about API Support.

Or, search our Help Center for even more.

Who's talking
Top contributors to this post