Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hi,
I am using the list_folder endpoint with the recursive arg. I am looking for a way (in javascript) to take the results and create an object that is organized into the nested file tree structure one would see while interacting with Dropbox. I am not from a CS background and may be unaware of a good algorithm for this, but regardless, I would love some help if anyone could lend a hand.
here is an example of the recursive response (paths only):
/l_one
/l_one/common
/l_one/common/2016
/l_one/common/2017
/l_one/common/2018
/l_one/common/2016/folder_one
/l_one/common/2016/folder_two
/l_one/common/2016/folder_three
/l_one/common/2016/folder_four
/l_one/common/2016/folder_five
/l_one/common/2017/folder_one
/l_one/common/2017/folder_two
/l_one/common/2017/folder_three
/l_one/common/2017/folder_four
/l_one/common/2017/folder_five
/l_one/common/2018/folder_one
/l_one/common/2018/folder_two
/l_one/common/2018/folder_three
/l_one/common/2018/folder_four
/l_one/common/2018/folder_five
/l_one/common/2016/folder_one/file_one.pdf
/l_one/common/2016/folder_one/file_two.pdf
/l_one/common/2016/folder_one/file_three.pdf
/l_one/common/2016/folder_two/file_one.pdf
/l_one/common/2016/folder_two/file_two.pdf
/l_one/common/2016/folder_two/file_three.pdf
/l_one/common/2016/folder_three/file_one.pdf
/l_one/common/2016/folder_four/file_one.pdf
/l_one/common/2016/folder_four/file_two.pdf
same idea for pdf's in 2017 and 2018
of course what i want is nested JS object:
fileTree = {
l_one: {
common: {
2016: {
folder_one: [*pdf's here*],
folder_two: [*pdf's here*],
...
...
},
2017: {...},
2018: {...}
}
}
any help is greatly appreciated!
* I am not necessarily looking for Dropbox api endpoint tips - if there is a better way to use list_folder, I am interested, but I am mostly looking for a javascript specific way of building this object.
I do think we missed the opportunity to take advantage of the has_more / continue feature of the API. My current deadline for a demo is too close to try that, but that is likely the best overall way. With that, I can build the Object I'm looking for step by step instead of having this challenge in front of me. Thanks for the tip, and yes - hope someone else has some insight for how to go about this.
Hi there!
If you need more help you can view your support options (expected response time for a 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!