我正在开发一个使用Node JS、Formidable和Cloudinary依赖关系的应用程序,该应用程序允许用户将图像上传到Cloudinary数据库。
用户将从多部分表单上传图像,我希望字段成为传递给Cloudinary upload函数的变量。
我的代码可以工作,但我在将表单信息作为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 image_name which is provided by the user from the form而不是var file_name
发布于 2016-03-03 17:41:30
顺便说一句,因为您提供了一个对parse()的回调,所以不需要处理end。该回调在触发end时调用。
用户输入的文本将为fields格式。
https://stackoverflow.com/questions/35678881
复制相似问题