[英]How to upload file to cloudinary using Node.js and Postman
I am uploading the file by Postman using Node js. 我正在使用Node js由邮递员上传文件。 Here I need to upload the file into Cloudinary.
在这里,我需要将文件上传到Cloudinary。 My Postman screen shot is given below:
我的邮递员屏幕截图如下:
I am providing my code below: 我在下面提供我的代码:
var multer = require('multer')
var cloudinary = require('cloudinary');
cloudinary.config({
cloud_name: 'sample',
api_key: '874837483274837',
api_secret: 'a676b67565c6767a6767d6767f676fe1'
});
var storage =multer.diskStorage({
destination: function (req, file, callback) {
callback(null, './uploads');
},
filename: function (req, file, callback) {
callback(null, Date.now()+'-'+file.originalname);
}
});
var upload = multer({ storage : storage });
app.post('/api/users/save-card-file',upload.single('file'), function (req, res, next) {
})
I am hosting my project in Heroku. 我正在Heroku托管我的项目。 Here I need to store that image file into Cloudinary and get the uploaded file URL as response.
在这里,我需要将该图像文件存储到Cloudinary中,并获取上载的文件URL作为响应。
Uploading image to Cloudinary with Node.js: 使用Node.js将图像上传到Cloudinary:
cloudinary.v2.uploader.upload("/home/my_image.jpg",
function(error, result) {console.log(result)});
In the result object you should get the url
and secure_url
for the uploaded image. 在结果对象中,您应该获取上载图像的
url
和secure_url
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.