I'm working on a "google drive"-like functionality in my app and stuck with the "rename a file" functionality: because firebase storage is run on google cloud and google cloud doesn't have a "rename" function this task appeared to be not that obvious to solve. (they have a "move" command which is too heavy for the rename as it first copies and then deletes a file)
However I store "descriptor" object in a firestore for every file. Among other data, that descriptor stores the filename which I use to display to users.
The only reason I was looking for an option to rename the file in the storage itself is because my users have an option to download each file - in this case the file name comes from the storage itself and I can't find a way to change it.
For this, I generate a link like below that user clicks to download a file:
<a href="https://...myurl.com/..path_to_file/Hook.docx?..token-here..." download="Hook111.docx" target="_blank"></a>
It appeared that the download
parameter is ignored by browsers if server returns the name in header
So I was hoping to update the name in storage using metadata of the file:
bucket.file(".../Hook.docx").setMetadata({name:"Hook11122.docx"})
but I'm getting this error
Error: Value 'Hook11122.docx' in content does not agree with value 'users/Corp9wBL7BSHMgQf4mMnOyS31mD3/drive/BkkS0TbJMCxPUR9uHb2A_Hook.docx'. This can happen when a value set through a parameter is inconsistent with a value set in the request.
There are probably other solutions to this problem, but is there a way to tell firebase storage to return a different/custom name when downloading a file from a link?