html5 - input type='file' How to store the fileList object obtained by uploading in the browser?
怪我咯
怪我咯 2017-05-16 13:43:11
0
1
657

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

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
阿神

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));
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template