0

I'm trying to upload an image to a specific folder and also set the public_id.

I read the documentation here: https://cloudinary.com/documentation/image_upload_api_reference

My code is:

cloudinary.v2.uploader.upload(
   localImagePath,
   {
      public_id: '/my_folder/my_public_id',
      folder: 'my_folder',
      resource_type: 'image',
      transformation: 'profile_image'
   },
   (err, url) => {
      if (err) return reject(err);
      return resolve(url);
   }
);

But the image is uplaoded to this path: 'my_folder/my_folder/my_public_id' instead of my_folder/my_public_id.

From the docs:

The public ID contains the full path of the uploaded asset, including the folder name

I tried everything, please help!

1 Answer 1

1

You're specifying the folder twice - once in the public_id and again in the folder option.

Given that you are passing both upload options, the resulting public_id of the image will be <folder>/<public_id>.

You can omit the folder parameter completely and you will be getting your expected result (/my_folder/my_public_id).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.