【问题标题】:Upload an image to cloudinary with specific public_id to a specific folder (node.js)将具有特定 public_id 的图像上传到 cloudinary 到特定文件夹(node.js)
【发布时间】:2023-03-23 10:28:02
【问题描述】:

我正在尝试将图像上传到特定文件夹并设置 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

来自文档:

公共 ID 包含上传资产的完整路径,包括 文件夹名称

我都试过了,请帮忙!

【问题讨论】:

    标签: cloudinary


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2019-01-25
      • 2021-04-18
      • 2018-07-30
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 2018-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多