【问题标题】:How to multiple image upload with React.js to Firebase如何使用 React.js 将多个图像上传到 Firebase
【发布时间】:2018-11-19 23:31:19
【问题描述】:

使用 react js 我需要将多个图像上传到 firebase 我尝试使用以下代码无法进行多个上传。

//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>

    )

}

【问题讨论】:

    标签: javascript reactjs firebase firebase-storage


    【解决方案1】:

    要处理多个文件,您需要循环输入的 files 属性。

    所以:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-03
      • 2018-07-03
      • 2020-07-27
      • 2021-04-07
      • 2018-12-22
      • 2021-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多