Hi i want to save the array of an input type file.
<input type="file" id="fuGerber" onchange="saveFiles(this.files)" multiple />
I already tried this:
localStorage.setItem('files',JSON.stringify(files));
OR this:
localStorage.setItem('files',JSON.stringify(files[0]));
but JSON.stringify returns empty "{}" or this in the second case "{"0":{}}" Does any one knows something to save it without lose nothing inside of the array.
This is what my array have:
Maybe you're missing using a file reader to actually read the data from the file input which you can then store in an array before you save it to
localStorage
.See this answer here.
Update:
So I finally realized what you were having trouble with after duplicating the issue in JSFiddle. The problem is FileList is NOT an array (see here), it's a custom list type. As a result the JSON encoder doesn't know how to encode properly.
To get the data from the FileList you have to manually create a file object of each File in the FileList, push each object to an array\, and then you will be able to stringify and set to localStorage.
Doing the above I was able to successfully save the files: View of files array in localStorage
See my code example:
JSFiddle
Cheers! I hope this helps :)
If you are trying save an array do this:
To save:
To recovery from localStorage:
Updated:
For a file check this link How to save an image to localStorage and display it on the next page?