· 1 min read
#009

How to Enable Multiple File Selection for HTML Input Element

programming frontend react

Problem

We could only select/upload one image file at a time with below code.

<input
    className="hidden"
    type="file"
    accept="image/*"
    onChange={handleImageUpload}
    ref={imagesInputRef}
/>

Solution

We could enable multiple file selection by adding multiple attribute to the input element.

<input
    +multiple
    className="hidden"
    type="file"
    accept="image/*"
    onChange={handleImageUpload}
    ref={imagesInputRef}
/>

If you enjoyed this post, consider subscribing.
Get my next post delivered to you.

All articles