Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to upload pictures cloudinary?

I write code simple code for upload images cloudinary. But somewhere have errors.

import axios from 'axios'

const uploadPic = async (media) => {
    try {
        const form = new FormData();
        form.append('file', media);
        form.append('upload_presets', 'social_media');
        form.append('cloud_name', 'tmcotem');
        const res = await axios.post(process.env.CLOUDINARY_URL, form)
        return res.data.url;
    } catch (error) {
        console.log(error);
    }
}
export default uploadPic;

CLOUDINARY_URL is CLOUDINARY_URL: "https:api.cloudinary.com/v1_1/tmcotem/image/upload

But I cant upload. Please help me. i dashboard cloudinary cloud name is tmcotem but top right bar written another cloud name. I try these cloud names. But cant it. when i upload image i get this error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Error: Request failed with status code 400
at createError (createError.js:16:1)
at settle (settle.js:17:1)
at XMLHttpRequest.onloadend (xhr.js:54:1)

>Solution :

There is no parameter in Cloudinary called upload_presets it should be upload_preset instead (see the upload() parameters for reference.

Also, you won’t need to pass the cloud_name in your form-data as it’s part of the URL you’re POSTing to so that line can be removed entirely.

Those two changes should resolve the upload issues.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading