I cannot upload image using unsigned upload, and I don't know why. here's my code

Options
elise
elise Member Posts: 1
edited June 2023 in Developer APIs

 if(pics.type === "image/jpeg" || pics.type === "image/png"){

        const data = new FormData();

        data.append("file", pics);

        data.append("upload_preset","chat-app");

        data.append("cloud_name", "myfapiassesment");

        fetch("https://api.cloudinary.com/v1_1/myfapiassesment/image/upload", {

            method:"post",

            body: data,

        }).then((res) => res.json())

          .then (data => {

            setPic(data.url.toString());

            setLoading(false);

        })

          .catch((err) => {

            console.log(err);

            setLoading(false);

        });

   

Tagged:

Answers

  • tia
    tia Member, Cloudinary Staff Posts: 24
    Options

    Hi there,

    Thanks for reaching out.

    Are you still having issues uploading? If so, can you please share any error messages that you are getting, and also the date and time of the failed upload(s)?

    From the logs on our end, I'm seeing two failed uploads where you did not include the upload preset. The other uploads I see as going through successfully.

    If you still have questions, just let us know.

    Kind regards,

    Tia