[英]Adding an already created folder to Google Drive in Android
I want use google drive in my android app to backup folders that contain text, image and video files. 我想在我的android应用中使用Google驱动器备份包含文本,图像和视频文件的文件夹。
My problem is that while I can upload each text, image and video file separately using the Drive API, I can't see a way to upload entire folders at once so that the organisation remains intact. 我的问题是,尽管我可以使用Drive API分别上传每个文本,图像和视频文件,但我看不到一种可以一次上传整个文件夹的方式,这样组织就可以保持完整。
The organisation of the folders is as follows: 文件夹的组织如下:
app>Projects>notes>photos/text/video app>项目>笔记>照片/文字/视频
Ideally I would like to upload the folder "app" and along with all of its contents while keeping the parent/child structure. 理想情况下,我希望在保留父/子结构的同时上载文件夹“ app”及其所有内容。
Are you using Google Drive Api for Android or the REST Api ? 您是否正在使用适用于Android的Google Drive Api或REST Api?
If you are using the REST API you can create a folder like this : 如果您使用的是REST API,则可以创建一个如下所示的文件夹:
private String createFolder() throws IOException {
File fileMetadata = new File();
fileMetadata.setName("FOLDER_NAME");
fileMetadata.setMimeType("application/vnd.google-apps.folder");
File file = mService.files().create(fileMetadata)
.setFields("id")
.execute();
String Folderid = file.getId();
And then with the file id you do this : 然后使用文件ID执行此操作:
File nFile= new File();
nFile.setName("FILE_NAME");
nFile.setParents(Collections.singletonList(Folderid));
File file = mService.nFile().create(fileMetadata).execute();
The setParents is used to create the file INSIDE the parent which is the folder just created in this example. setParents用于在父文件内部创建文件,父文件是本示例中刚刚创建的文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.