I'd like for my users to be able to re-name a file before uploading it.
I have a File
object in Javascript which has a name
property that is already set, but i'd like for this to be able to be updated. Right now doing the obvious myFile.name = "new-name.txt"
returns an error that this property is read only.
What's the best way of changing the name
property on a JavaScript File
object?
Now that file.name
is a read-only property, I've found this to be the best method to rename a File object in the browser:
const myNewFile = new File([myFile], 'new_name.png', {type: myFile.type});