Google Drive Rest API v3-如何将文件移至回收站? [英] Google Drive Rest API v3 - how to move a file to the trash?
问题描述
Google Drive Rest API v3具有Drive.Files.Delete方法,但是该方法会永久删除该文件.如何将文件移至回收站?
The Google Drive Rest API v3 has a Drive.Files.Delete method, but that permanently deletes the file.How do i move the file to the trash?
我查看了用于更新文件元数据的文档,但我尝试这样做,但似乎不起作用:
I looked at the docs for updating file metadata, and i tried to do this, but it doesn't seem to work:
File file = new File();
file.setTrashed(true);
driveService.files().update(f.getId(), file).execute();
推荐答案
I don't see any error with your code on how to move a file to trash wherein you'll use files.update
with {'trashed':true}
.
此线程中的代码示例:
解决方案是创建一个空的File设置,仅设置新值:
The solution is to create an empty File setting only the new values:
File newContent = new File();
newContent.setTrashed(true);
service.files().update(fileId, newContent).execute();
我已经在Google云端硬盘中尝试过此操作尝试一下!并将文件成功移至回收站.
I have tried this in Google Drive Try it! and successfully moved the file to trash.
只需确保File
引用com.google.api.services.drive.model.File
,并且不是 java.io.File
.
Just make sure that the File
refers to com.google.api.services.drive.model.File
and it is not java.io.File
.
这篇关于Google Drive Rest API v3-如何将文件移至回收站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!