I have a FileList like this:
FileList {0: File, 1: File, 2: File, File…}
I need to remember these files after pages has been refreshed. How can I save them to cookies? (or is there some better methods?) Right now I'm doing it like this $.cookie("result", files); files = $.cookie("result");
but this gets me [object FileList] which I can't parse. Turning files
into JSON didn't work either.
Any ideas how can I save the FileList so that I can loop it after page refresh?
EDIT: Maybe I should note that I get the FileList from user input e.g. "Choose files".
Assigning files:
HTML part:
<input type="file" id="files" name="file" multiple />
JS part:
$('#files').on('change', readFiles);
function readFiles(event) {
var files = event.target.files; //has FileList {0: File, 1: File, 2: File, File…}
$.cookie.json = true; //converts FileList to json (is correct).
$.cookie("result", files); //cookie registering also works (atleas with strings)
files = $.cookie("result"); //get undefined as a result
for (var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
reader.readAsText(f, 'utf-8');
}
}