简体   繁体   English

将图像上传到 Cloudinary

[英]uploading images to Cloudinary

I am trying to upload files directly to Cloudinary using nodejs.我正在尝试使用 nodejs 将文件直接上传到 Cloudinary。 I have gotten in to work successfully, but ONLY when I manually set the path of the image I am going to be upload, like so:我已经成功地工作了,但只有当我手动设置我要上传的图像的路径时,像这样:

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

but when I do this:但是当我这样做时:

cloudinary.uploader.upload(data.image)

it does not work.这没用。 A sample of my entire function is below.我的整个 function 的样本如下。 I need it to work like this because when I allow others (not on my local machine) to upload images, it will not work.我需要它像这样工作,因为当我允许其他人(不在我的本地机器上)上传图像时,它不会工作。

 // 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)

When running the upload call from the root folder it searches for the image in the same folder.从根文件夹运行上传调用时,它会在同一文件夹中搜索图像。 You can run the upload from the img folder.您可以从img文件夹运行上传。 eg cd./public/css/img/ and then call the upload. eg cd./public/css/img/然后调用上传。 or use the full path as you did.或像您一样使用完整路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM