search

Home  >  Q&A  >  body text

html5 - input type='file' How to store the fileList object obtained by uploading in the browser?

let files = e.target.files;
localStorage.setItem('files',JSON.stringify(files));
The storage result is: {"0":{}}
How Solved, waiting online...

怪我咯怪我咯2794 days ago673

reply all(1)I'll reply

  • 阿神

    阿神2017-05-16 13:45:11

    e.target.files is not an array, so it needs to be converted into an array.

    Array.from
    

    Each item of data is a File object. If you want to store the file name, you can take the name attribute.

    The code is probably like this:

    let files = Array.from(e.target.files).map(x => x.name);
    localStorage.setItem('files',JSON.stringify(files));
    

    or

    let files = [...e.target.files].map(x => x.name);
    localStorage.setItem('files',JSON.stringify(files));
    

    reply
    0
  • Cancelreply