2

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();
Guest1997
  • 479
  • 9
  • 23

1 Answers1

7

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.

Community
  • 1
  • 1
abielita
  • 12,662
  • 2
  • 16
  • 55