简体   繁体   中英

Renaming a file along with extension in Google Drive

I have uploaded a file as filename.txt , I wanted to rename it as filename.java so I executed this code

File file = new File();
file.Title = "filename.java";
FilesResource.PatchRequest request = service.Files.Patch(file, fileId);
File updatedFile = request.Execute();

File has been updated with new title as filename.java . But When I am downloading this file, the file name appears as filename.java.txt . So why is it adding extension of previous file name to updated file name? And How to overcome this?

The fileExtension is documented to be read-only and determined at creation time :

fileExtension string The file extension used when downloading this file. This field is read only. To set the extension, include it on title when creating the file. This is populated only for files with content stored in Drive.

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