且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Google Drive V2 Java API - 将文件上传到特定文件夹

更新时间:2022-11-05 11:58:13

您可以通过在元数据中设置父项字段直接在指定文件夹中创建文件。

  {
title:test.jpg,
mimeType:image / jpeg,
parents:[{
kind:驱动器#文件,
id:< folderId>
}]
}

这就是我在Python中所做的,但我相信在java中有一个相关的。


Following is the method adopted to upload file to specific folder using Gdrive V2 sdk. 1) insert file to root folder (Drive.Files.insert(File,AbstractInputStream) 2) Delete the root parent reference of the new uploaded file 3) Add the specific target folder as the new parent reference to the file.

The above works. But, if network is slow, we see the file sitting at the Root folder for quite some time before it moves to the specific target folder. How can we avoid this? Can we batch all the above three operations? But AFAIK, batching is supported for operations of a particular type like..we can batch only all Files operations or Parent operations or Revision operations. Can we batch operations belonging to different types, for example (Files.insert() and Parent.delete())?

Inputs will be appreciated.

Thanks!!

you can create file in specified folder directly by setting parents field in metadata.

{
  "title" : "test.jpg",
  "mimeType" : "image/jpeg",
  "parents": [{
    "kind": "drive#file",
    "id": "<folderId>"
  }]
}

This is what I am doing in python, but I believe there is a relevant in java.