How to change name of file in javascript from input=File

后端 未结 3 963
情深已故
情深已故 2021-02-01 19:29

I need to change the filename (not the file, just the metadata of the name) when uploading to a sharepoint site.

I figured that it would be easy enough to change the htm

3条回答
  •  臣服心动
    2021-02-01 20:33

    A simpler and more memory efficient approach - change the file's 'name' property to writeable:

    Object.defineProperty(fileToAmend, 'name', {
      writable: true,
      value: updatedFileName
    });
    

    Where fileToAmend is the File and updatedFileName is the new filename.

    Method from Cannot assign to read only property 'name' of object '[object Object]'

提交回复
热议问题