问题
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