We were looking to keep the original file-name of the revision file being uploaded in the history list when the actual file in Google drive had a different name.
We wanted the Google drive file to be named with a static name and all the revisions in the history list to contain the date in their file-names.
There is not direct functionality available to do that through the Google Drive API.
The natural thing springing into mind was to update the revision's originalFilename field through the API (we are using NodeJS with module "googleapis" v3)
service.revisions.update(
{
fileId: <fileId>,
revisionId: <revisionId>,
resource: {
originalFilename : <revision file name>
}
}
)
But the response was :
{
Error: The resource body includes fields which are not directly writable.
code: 403,
errors:
{
domain: 'global',
reason: 'fieldNotWritable',
message: 'The resource body includes fields which are not directly writable.'
}
}
So it turned out the originalFilename field was recognizable on revisions.update but somehow not updatable - may be done like that on purpose for some reason.
The workaround that we used which actually managed to achieve our initial goal was to programmatically :
- Rename the google drive file, before uploading the revision, to the revision's file name
- Upload the revision to the google drive ( now the originalFilename of the revision is being automatically set to the actual file name which we conveniently renamed on the previous step to be the revisions file name )
- Rename the google drive file to its original file name
So if we have google drive file named "GooleDriveFile.dat" and we want to upload revision named GooleDriveFile_01012016.dat and to keep the original revision name in the history list we can programmatically :
1-> rename the google drive file from GooleDriveFile.dat to GooleDriveFile_01012016.dat
service.files.update(
{
fileId : <fileId>,
resource: {
name: "GooleDriveFile_01012016.dat",
},
fields : "id,headRevisionId"
}
)
2-> Upload the revision to the google drive
service.files.update(
{
fileId : <fileid>,
newRevision : true,
keepRevisionForever : true,
media: {
body: fs.createReadStream(<local path to the revision file>)
},
fields : "id,headRevisionId"
}
)
3-> Rename the google drive file back to "GooleDriveFile.dat"
service.files.update(
{
fileId : <fileId>,
resource: {
name: "GooleDriveFile.dat",
},
fields : "id,headRevisionId"
}
)