I am trying to upload multiple images to firebase storage simultaneously and then call them down into a firebase database. I have this working with singular images, but I am not sure how I need to modify my code to allow multiple images. When I select multiple images to be uploaded, they successfully upload to firebase storage, however, only the first image uploaded will be assigned to the featuredImage array and therefore displayed. Any help would be much appreciated.
Here is my code:
class OtherEdit extends Component {
constructor(props) {
super(props);
this.state={
id: '',
info: {
title: '',
subtitle: ''
},
article: {
featuredImage: []
}
}
}
...
uploadImageCallBack = (e) => {
return new Promise(async(resolve, reject) => {
const file = e.target.files[0]
const fileName = uuidv4()
storageRef.ref().child("OtherMedia/" + fileName).put(file)
.then( async snapshot => {
const downloadURL = await storageRef.ref().child("OtherMedia/" +fileName).getDownloadURL()
resolve({
success: true,
data: {link: downloadURL},
})
})
})
}
...
<FormGroup className='edit-featured-image'> Featured images
<Input type="file" multiple accept='image/*' className="image-uploader"
onChange={async (e) => {
const uploadState = await this.uploadImageCallBack(e)
if(uploadState.success) {
await this.setState({
hasFeaturedImage: true,
article: {
...this.state.article,
featuredImage: uploadState.data.link
}
})
}
}}>
</Input>
<div className='image'>
{
this.state.hasFeaturedImage ?
<img src={this.state.article.featuredImage} /> : ''
}</div>
</FormGroup>