【发布时间】:2016-06-11 06:31:41
【问题描述】:
我正在开发一个使用 Node JS、Formidable 和 Cloudinary 依赖项的应用程序,它允许用户将图像上传到 Cloudinary 数据库。
用户将从多部分表单上传图像,我希望这些字段成为传递给 Cloudinary 上传功能的变量。
我的代码有效,但我在将表单信息作为 Cloudinary 参数传递时遇到问题。
这是我当前的代码,它传递了原始文件名:
router.post('/upload', function (req, res){
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end(util.inspect({fields: fields, files: files}));
});
form.on('end', function(fields, files) {
var temp_path = this.openedFiles[0].path;
var file_name = this.openedFiles[0].name;
cloudinary.uploader.upload(temp_path, function(result) { console.log(result) },
{ public_id: file_name });
})
但我不想要原始文件名。而不是var file_name 我想要var image_name which is provided by the user from the form
【问题讨论】:
标签: javascript node.js cloudinary formidable