Skip to content

Guidance on Multiple File Uploads with Alt Text #913

Answered by edmundhung
andrecasal asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @andrecasal,

Thanks for the question! File input is indeed a tricky one.

The challenge is that the browser doesn't allow setting a value on an for security reasons

That was my understanding as well. But someone suggest that the DataTransfer API might work, which I think can be used to set the files through a ref callback:

<input
  type="file"
  name={imageFields.file.name}
  ref={element => {
    const image = images[index]
    if (element && image) {
       const fileList = new DataTransfer()
       fileList.items.add(image)

       // Set the files to the input
       element.files = fileList.files;
    }
  }}
/>

Can you give it a try and let me know how it goes?

As a side notes, i…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by andrecasal
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants