How to create a modified copy of a File object in JavaScript?
问题 Properties of files received from an <input type="file"> are read-only. For example, the following attempt to re-write file.name would either fail silently or throw TypeError: Cannot assign to read only property 'name' of object '#<File>' . <input onchange="onchange" type="file"> onchange = (event) => { const file = event.target.files[0]; file.name = 'foo'; } Attempting to create a copy via Object.assign({}, file) fails (creates an empty object). So how does one clone a File object? 回答1: My