我正在尝试使用另一个 Google 文档文件的内容更新一个 Google 文档文件的内容。我不使用 API 的 copy
方法的原因是它会创建另一个具有另一个 ID 的文件。我的目标是保留文件的当前 ID。不幸的是,这是一个没有执行任何操作的代码片段:
com.google.api.services.drive.Drive.Files.Get getDraft = service.files().get(draftID);
File draft = driveManager.getFileBackoffExponential(getDraft);
com.google.api.services.drive.Drive.Files.Update updatePublished = service.files().update(publishedID, draft);
driveManager.updateFileBackoffExponential(updatePublished);
两个 backoffExponential 函数只是在对象上启动 execute
方法。
谷歌搜索后我发现 update
方法提供了另一个构造函数:
public Update update(java.lang.String fileId, com.google.api.services.drive.model.File content, com.google.api.client.http.AbstractInputStreamContent mediaContent)
问题是,我不知道如何检索 Google 文件(例如 Google 文档)的媒体内容。
最后的手段可能是 Google Apps 脚本,但我宁愿避免这样做,因为它非常慢且不可靠。
谢谢。
编辑:我正在使用 Drive API v3。
最佳答案
Updates a file's metadata and/or content with patch semantics.
This method supports an /upload URI and accepts uploaded media with the following characteristics:
Maximum file size: 5120GB Accepted Media MIME types: /*
要以可用的格式下载 Google 文件,您需要指定 mime 类型。由于您使用的是电子表格,因此可以尝试 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet。 Link to Download files了解更多信息。
关于java - 如何更新 Google 云端硬盘中的文件内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37673876/