Skip to content
This repository was archived by the owner on Jun 5, 2022. It is now read-only.
This repository was 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

Description

@HammadAli-WD

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions