简体   繁体   中英

Can't update file name in Google Drive

I am trying to update a file in Google Drive using Java.

File f =
drive.files().update(fileId, null).setAddParents(newParentId).setRemoveParents(oldParentId).set("name", "new name").execute();

The parent folder is updated, but the file name is not updated.

What am I doing wrong?

Filename or title belongs to metadata according to Working with File and Folder Metadata guide.

"Metadata is encapsulated in the Metadata class and contains all details about a file or folder including the title, the MIME type, and whether the file is editable, starred or trashed."

To change/update a metadata, you'll be using MetadataChangeSet .

"The metadata may be set or changed when creating or updating a file by using a MetadataChangeSet, setting the appropriate values, and then calling the DriveResource.updateMetadata method."

MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setStarred(true)
.setIndexableText("Description about the file")
.setTitle("A new title").build(); //change/update demo
file.updateMetadata(getGoogleApiClient(), changeSet)
.setResultCallback(metadataCallback);

Full sample is in Android drive demo .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM