Languages
[Edit]
EN

React - multiple files input

3 points
Created by:
maryam
1181

In this article, we would like to show you how to upload multiple files in React.

Multiple files upload form in React.
Multiple files upload form in React.

There are two main approaches how to let users to select multiple files:

  • using multiple property with input element that allows to select in many files per one input,
  • using multiple input elements that each one input let's user to select only one file.

In this article, we want to show how to use the second option.

The below example uses multiple <input type="file" /> elements that help us to select files from a computer and upload them with fetch() method that uses FormData class object to wrap files like classic form element submit action does, but here we send it via AJAX / XHR request. It is very important to give for each input element proper name to be able to distinct it on the server - the below example uses file1, file2 and file3.

Runnable example:

Important:

  • each file must be given a name,
  • the number of occurrences of the <input type = "file" /> element indicates the number of files that we send to send to the server.

Alternative titles

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

ReactJS

React - multiple files input
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join