ssa
ssa

Reputation: 309

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?

Upvotes: 1

Views: 2830

Answers (1)

CodeCaster
CodeCaster

Reputation: 151720

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.

Upvotes: 2

Related Questions