Google Drive V2 Java API - 将文件上传到特定文件夹 [英] Google Drive V2 Java API - Upload file to specific folder

查看:198
本文介绍了Google Drive V2 Java API - 将文件上传到特定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是使用Gdrive V2 sdk将文件上传到特定文件夹的方法。
1)将文件插入根文件夹(Drive.Files.insert(File,AbstractInputStream)
2)删除新上传文件的根父引用
3)将特定目标文件夹添加为新文件的父引用。



以上作品。
但是,如果网络速度很慢,我们会在文件移到特定目标文件夹之前看到它位于Root文件夹中一段时间​​。我们如何避免这种情况?我们可以批量上述三种操作吗?但AFAIK,批处理支持特定类型的操作,比如..我们只能批量所有文件操作或父操作或修订操作。我们可以批量操作属于不同的类型,例如(Files.insert()和Parent.delete())?
$ b

谢谢!!

解决方案

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

  {
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.

这篇关于Google Drive V2 Java API - 将文件上传到特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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