使用 Node 和 Express 从 Cloudinary 删除图像

问题描述 投票:0回答:2

我正在尝试使用node从cloudinary删除图像,我已阅读文档,代码如下

cloudinary.v2.uploader.destroy(public_id, options, callback);

我已经尝试过这种方法,但我不断收到上传程序未定义的错误,所以我认为它使用的是您用来初始化 multer 的名称,我就是这样做的

const parser = multer({ storage: storage });

但是,它仍然向我显示“解析器未定义”,所以我对如何继续这个感到困惑,我希望有人可以帮助我解决这个问题,因为我不久前看到了类似的问题答案,答案仍然是和我说的一样,所以我不知道文档是否改变了。 谢谢!!

node.js express cloudinary
2个回答
0
投票

你可以尝试:

var cloudinary = require('cloudinary');

cloudinary.config({ 
    cloud_name: "########", 
    api_key: "########", 
    api_secret: "########" 
}); 
cloudinary.v2.uploader.destroy('sample', function(error,result) {
  console.log(result, error) });

0
投票

尝试使用这个 -

import { v2 as cloudinary } from "cloudinary";

cloudinary.config({ 
 cloud_name: `${process.env.CLOUD_NAME}`, 
  api_key: `${process.env.CLOUD_API_KEY}`, 
  api_secret: `${process.env.CLOUD_API_SECRET}`, 
});

const response = await cloudinary.uploader.upload(localFilePath, {
    resource_type: "auto", 
});
return response;
© www.soinside.com 2019 - 2024. All rights reserved.