将特定 public_id 的图像上传到 cloudinary 到特定文件夹 (node.js)

Upload an image to cloudinary with specific public_id to a specific folder (node.js)

我正在尝试将图像上传到特定文件夹并设置 public_id。

我在这里阅读了文档:https://cloudinary.com/documentation/image_upload_api_reference

我的代码是:

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);
   }
);

但是图片上传到这个路径:'my_folder/my_folder/my_public_id' 而不是 my_folder/my_public_id.

来自文档:

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

我都试过了,请帮忙!

您指定了两次文件夹 - 一次在 public_id 中,另一次在 folder 选项中。

鉴于您同时传递了两个上传选项,生成的图像 public_id 将是 <folder>/<public_id>

您可以完全省略 folder 参数,您将得到预期的结果 (/my_folder/my_public_id)。