Categories
JavaScript Answers

How to upload multiple files using JavaScript formData?

Spread the love

To upload multiple files using JavaScript formData, we call append with an array key.

For instance, we write

fd.append("fileToUpload[]", document.getElementById("fileToUpload").files[0]);

to call fd.append with the "fileToUpload[]" array key and a file we get from a file input.

We get the file input with getElementById.

And we get the selected files from the files property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *