How to create a modified copy of a File object in JavaScript?

后端 未结 3 924
刺人心
刺人心 2020-12-09 17:48

Properties of files received from an are read-only.

For example, the following attempt to re-write file.name w

3条回答
  •  我在风中等你
    2020-12-09 18:06

    A more cross browser solution

    The accepted answer works for me too in modern browsers, but unfortunately it does not work in IE11, since IE11 does not support the File constructor. However, IE11 does support the Blob constructor so it can be used as an alternative.

    For example:

    var newFile  = new Blob([originalFile], {type: originalFile.type});
    newFile.name = 'copy-of-'+originalFile.name;
    newFile.lastModifiedDate = originalFile.lastModifiedDate;
    

    Source: MSDN - How to create a file instannce using HTML 5 file API?

提交回复
热议问题