36

I have a list of file object like:

var files = [File, File, File]

I want to convert it to something like:

I have a file field where I want to map my files as FileList object.

var uploading_files = {}
files.forEach(function(file, key) {
    uploading_files[key] = file

})
var uploader = document.getElementById('uploader')
uploader.files = uploading_files

console.log(uploader.files)

But It does not give me FileList object ? How can I create a file list objecdt ? Thanks in advance..

5
  • what is the error in your console log? Commented Jul 19, 2016 at 4:11
  • It gives me emptly FileList Object.. No files assigned to it Commented Jul 19, 2016 at 4:24
  • 1
    At the end how did you accomplish it? I am facing same issue as of now. Commented Sep 14, 2020 at 11:08
  • I'm also interested to know if you ever accomplished this. Commented Jan 18, 2022 at 19:46
  • I am working with a similar situation. You can iterate through each element in the array of files, and append to a form object, with a custom id, say a relative file path. Using Fetch API you can easily upload files with other form contents and fetch the list of files using $_FILES to iterate through each key, and upload the files to the server or database. It is worth noting that You must use the actual File Object when using the FormData API and store each file seperately. On the server side it should appear as a FileList. So you may implement your own FileList object to implement this Commented Feb 5, 2022 at 18:35

1 Answer 1

44

The FileList object is "read-only" and has no implementation of its constructor.

Visit this page: FileList On MDN

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.