使用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>
)
}
最佳答案
要处理多个文件,您需要循环输入的 files
属性。
所以:
const storageRef = fire.storage().ref();
this.state.file.forEach((file) => {
storageRef
.child(`images/${file.name}`)
.putFile(file).then((snapshot) => {
})
});
关于javascript - 如何使用 React.js 将多个图像上传到 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50785465/