0

I upload images on one of reactjs project and host on imgbb but sometimes posting is working successfully and sometimes showing error.message: "Can't get target upload source info". What's the problem actually ?

 const [coverPhoto, setCoverPhoto] = useState([]);

    const onChangeCover = (data) => {

        setCoverPhoto(data)

        const imgAPIKey = 'c83daa0cd70c09ca51b747864c4a22e1'
        const image = data[0].file
        const formData = new FormData()
        formData.append('image', image)
        const url = `https://api.imgbb.com/1/upload?key=${imgAPIKey}`
        fetch(url,
            {
                method: "POST",
                body: formData

            })
            .then(res => res.json())
            .then(async result => {
                console.log('imgbbCover', result)
                const coverPhoto = result.data.url
                await fetch(`http://localhost:5000/profiles/${email}`,
                    {
                        method: 'PUT',
                        headers: {
                            'content-type': 'application/json',
                        },
                        body: JSON.stringify({ coverPhoto })
                    })
            })

    }

see the console

0

Browse other questions tagged or ask your own question.