Renaming a File() object in JavaScript
try this:
var blob = file.slice(0, file.size, 'image/png');
var newFile = new File([blob], 'name.png', {type: 'image/png'});
note: this is for a image type, you have to change this type with type you're actually using.
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});