cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

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: 

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

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

sixdesign
Explorer | Level 4
Go to solution

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

TaylorKrusen
Dropbox Staff
Go to solution

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:50:38Z",
            "server_modified": "2015-05-12T15:50:38Z",
            "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. 

View solution in original post

4 Replies 4

TaylorKrusen
Dropbox Staff
Go to solution

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:50:38Z",
            "server_modified": "2015-05-12T15:50:38Z",
            "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. 

sixdesign
Explorer | Level 4
Go to solution

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!

Greg-DB
Dropbox Staff
Go to solution

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.

sixdesign
Explorer | Level 4
Go to solution

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

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    sixdesign Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    TaylorKrusen Dropbox Staff
What do Dropbox user levels mean?