2

using react js I need multiple image upload to firebase I tried with below code is not working to multiple upload.

//display multi
handleChange(event) {

    const file = Array.from(event.target.files);
    this.setState({ file });   
}
//upload multi
fileuploadHandler = () => {

    const storageRef = fire.storage().ref();
    storageRef.child(`images/${this.state.file.name}`)
        .putFile(this.state.file).then((snapshot) => {

    });
  }

render() {
    return (
        <div className="App">
            <input id="file" type="file" onChange={this.handleChange.bind(this)} required multiple />
            <button onClick={this.fileuploadHandler}>Upload!</button>               
            </div>

    )

}

1 Answer 1

3

To handle multiple files, you'll need to loop over the files property of the input.

So:

const storageRef = fire.storage().ref();
this.state.file.forEach((file) => {
  storageRef
      .child(`images/${file.name}`)
      .putFile(file).then((snapshot) => {
  })
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.