gpt4 book ai didi

java - 如何更新 Google 云端硬盘中的文件内容?

转载 作者:太空宇宙 更新时间:2023-11-04 12:32:43 25 4
gpt4 key购买 nike

我正在尝试使用另一个 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。

最佳答案

尝试Google Drive REST update .

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com