如何以编程方式将文件夹上传到Google驱动器 [英] How to upload a folder to Google drive programmatically

查看:71
本文介绍了如何以编程方式将文件夹上传到Google驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式将文件夹上传到我的android应用中的Google驱动器.有没有可以让我在保留目录结构的同时将我的android设备中的整个文件夹上传/复制到Google驱动器的api?

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.

推荐答案

您有2种不同的方法来实现.具体来说,有两种不同的API,分别是 REST Api GDAA .

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/查找根文件夹
2/将其用作第一级文件夹的父级,并创建一个(如果不存在)
3/洗涤,冲洗,重复直到达到文件级别
4/创建带有父参考的文件

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

如果您不知道目录结构的深度,则可以递归地实现它,否则可以使用意大利面条"方法("for"循环).

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

祝你好运

这篇关于如何以编程方式将文件夹上传到Google驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆