【问题标题】:uploading images to Cloudinary将图像上传到 Cloudinary
【发布时间】:2021-03-20 02:06:26
【问题描述】:

我正在尝试使用 nodejs 将文件直接上传到 Cloudinary。我已经成功地工作了,但只有当我手动设置我要上传的图像的路径时,像这样:

cloudinary.uploader.upload('./public/css/img/' + data.image)

但是当我这样做时:

cloudinary.uploader.upload(data.image)

它不起作用。下面是我的整个函数的示例。我需要它像这样工作,因为当我允许其他人(不在我的本地机器上)上传图像时,它不会工作。

 // collected image from a user
        const data = {
            image: req.query.image,
          }
          console.log(data)
          // upload image here
          cloudinary.uploader.upload(data.image)
          .then((result) => {
              // response.status(200).send({
              //   message: "success",
              //   result,
              // });
              console.log(result.secure_url)

【问题讨论】:

    标签: javascript java html node.js cloudinary


    【解决方案1】:

    从根文件夹运行上传调用时,它会在同一文件夹中搜索图像。您可以从img 文件夹运行上传。例如cd ./public/css/img/ 然后调用上传。或像您一样使用完整路径。

    【讨论】:

    • 如果我想从本地计算机上的任何文件夹上传照片,我可以这样做吗?
    猜你喜欢
    • 2015-02-21
    • 2017-07-12
    • 2014-11-25
    • 2018-03-15
    • 2017-12-01
    • 2021-03-08
    • 2016-05-18
    • 2012-10-11
    • 2014-07-23
    相关资源
    最近更新 更多