on upload, uploading the first image two times
Hi ,
I am using the following code for uploading images, but when i check the array in db the first images uploaded two times. the problem occurs by selecting the images on by one.
onFileChange=(e) => {
/* this.setState({ imgCollection: [...this.state.imgCollection, ...e.target.files] }) */
this.setState({ imgCollection: this.state.imgCollection.concat(e) })
}
const formData = new FormData();
this.state.imgCollection.forEach(image => formData.append('imgCollection', image))
fetch('http://localhost:3005/apiHost/roomInputs', { method: 'POST', body: formData })
.then(res => {
console.log(res)
if (res.ok) {
this.props.history.push("/")
} else {
this.props.history.push("/roomData")
}})
<ImageUploader withIcon={false} name="imgCollection" buttonText='Choose images' onChange={this.onFileChange} imgExtension={['.jpg', '.gif', '.png', '.gif']} maxFileSize={5242880} withPreview={true} />