Google Drive Rest API v3-如何将文件移至回收站? [英] Google Drive Rest API v3 - how to move a file to the trash?

查看:637
本文介绍了Google Drive Rest API v3-如何将文件移至回收站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

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