【问题标题】:Iron Router to receive multi part form POST FilesIron Router 接收多部分形式的 POST 文件
【发布时间】:2015-07-19 00:00:40
【问题描述】:

如何使用 Iron Router 制作服务器端路由,该路由将接受对给定 URL 的 POST 请求并接收 POST 发送的 FILE/Image ?我使用 Collection FS 作为图像上传器和 Grid FS 来存储图像我想要做的是使用 Iron Router 接收 POST url 并从 POST 中提取文件并使用 Collection FS 或任何其他图像上传器来上传该文件。我使用 POST url 而不仅仅是模板事件处理程序来上传的原因是,我使用的文本编辑器是使用 POST 提交到服务器来上传图像。

【问题讨论】:

    标签: javascript node.js meteor iron-router


    【解决方案1】:

    经过一番搜索,this package 似乎做了你想做的事。 HTTP 方法目前在 meteor's roadmap 上,这看起来是一个不错的解决方案。

    【讨论】:

      【解决方案2】:

      你可以试试busboy https://github.com/mscdex/busboy

      在铁路由器一侧

      this.route('/upload', {
          where: 'server',
          method: 'POST',
          name:'upload',
          onBeforeAction: (function (req, res, next) {
              //busboy code here 
          var busboy = new Busboy({ headers: req.headers });
          busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
              console.log('File [' + fieldname + ']: filename: ' + filename + ',    encoding: ' + encoding + ', mimetype: ' + mimetype);
              file.on('data', function(data) {
                  console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
              });
              file.on('end', function() {
                  console.log('File [' + fieldname + '] Finished');
              });
          });
          busboy.on('field', function(fieldname, encoding, mimetype) {
              console.log('Field [' + fieldname + ']: value: ' + inspect(val));
          });
          busboy.on('finish', function() {
              console.log('Done parsing form!');
              res.writeHead(303, { Connection: 'close', Location: '/' });
              res.end();
              next();
          });
          req.pipe(busboy);
      });  
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-11-05
        • 1970-01-01
        • 1970-01-01
        • 2015-08-30
        • 2014-12-31
        • 1970-01-01
        • 2010-09-11
        相关资源
        最近更新 更多