【问题标题】:Node JS, Formidable, Cloudinary Image UploadNode JS,强大,云图上传
【发布时间】: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


    【解决方案1】:

    顺便说一句,没有必要处理end,因为您提供了对parse() 的回调。当end 被触发时调用回调。

    用户输入的文本将在fields中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-01
      • 2016-12-01
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多