How to upload a folder to Google drive programmatically

匆匆过客 提交于 2019-12-10 23:50:17

问题


I want to upload a folder to Google drive in my android app programmatically. Is there an api which would let me upload / copy an entire folder in my android device to Google drive while preserving the directory structure?

All documentation and examples only talk about file uploads but not folder.


回答1:


You have 2 different ways to do it. Specifically, 2 different APIs, the REST Api and the GDAA.

Basically, the algorithm goes like this:

1/ find root folder
2/ use it as a parent of your first level folder and create one (if not exist)
3/ wash, rinse, repeat until you reach your file level
4/ create a file with parent reference

You implement it recursively if you don't know your directory structure depth, otherwise you can use a 'spaghetti' approach ('for' loop).

You can see an implementation of this problem in the 'createTree()' method in this demo for the REST Api, or you can implement it under GDAA.

You can also look at this, this and this SO answer to get better understanding of the problem

Good Luck



来源:https://stackoverflow.com/questions/34327047/how-to-upload-a-folder-to-google-drive-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!