Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to combine two FileList objects?

I have a FileList object which holds previously uploaded documents. I'm trying to use another function to add more files to this collection, by using another FileList object, so I need to "append" the secondary FileList object onto the primary one. How would it be possible to achieve this?

like image 235
instant_gravelication Avatar asked May 07 '15 20:05

instant_gravelication


People also ask

How do I loop a FileList?

One way to let us loop through each item in a file list object is to convert it to an array with the Array. from method. Then we can use the forEach method on it to loop through the file list entries. The file input has the multiple attribute so that we can select multiple files.

Is FileList an array?

A FileList is an array-like object that represents a collection of File objects returned by the files property of the HTML <input> element. You can use this to access the list of files selected with the <input type="file"> element.

What is FileList used for?

FileList is a command-line utility that generates a CSV file listing the contents of a given directory. By default, the list includes the file name, size, and path, as well as the last-access, last-modified, and creation dates, etc. You can easily import all results to a spreadsheet or database.


2 Answers

You have to first convert the FileList objects to Arrays, after which you can simply concat the multiple arrays.

const joined = Array.from(fileListA).concat(Array.from(fileListB));
like image 146
levi Avatar answered Oct 20 '22 03:10

levi


const filesArray = [...filesList1, ...filesList2];
console.log(filesArray) // [File, File, File, File, File, ...]
like image 36
Roko C. Buljan Avatar answered Oct 20 '22 03:10

Roko C. Buljan