Skip to content
This repository has been archived by the owner on Jun 5, 2022. It is now read-only.

on upload, uploading the first image two times #211

Open
HammadAli-WD opened this issue Feb 28, 2021 · 0 comments
Open

on upload, uploading the first image two times #211

HammadAli-WD opened this issue Feb 28, 2021 · 0 comments

Comments

@HammadAli-WD
Copy link

HammadAli-WD commented Feb 28, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant