Reputation: 659
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();
Upvotes: 6
Views: 6947
Reputation: 13469
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}
.
Sample code in this thread:
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();
I have tried this in Google Drive Try it! and successfully moved the file to trash.
Just make sure that the File
refers to com.google.api.services.drive.model.File
and it is not java.io.File
.
Upvotes: 12