【问题标题】:how to check the progress of file uploading using formdata in node.js?如何使用node.js中的formdata检查文件上传的进度?
【发布时间】:2016-07-29 06:28:51
【问题描述】:

我想检查第三台服务器中文件上传的百分比。 下面是我的控制器代码。 将文件上传到第三个服务器。

BASE.APP.post('/uploadFile/:request/:file', function (req, res, next) {

    //var form = new BASE.multiparty.Form();
    var path = 'uploads/'+req.params.file;
    var fstream = BASE.FS.createReadStream(path);
    //form.on('part', function(part) {
    //  console.log('inside');



        var url =   req.usersession.webipAddress;

/*  var formData = {
      file: {
        value: BASE.FS.createReadStream(path),
        options: {
          fileNameUnique: req.params.file
        }
      }
    };

    // Post the file to the upload server
    BASE.request.post({url: url+'test/service/uploadFile/', formData: formData});*/
     /*var form = new BASE.FormData();
            form.append('fileNameUnique', req.params.file);

            form.append( 'file',fstream);
        */
        var formData = {
            fileNameUnique: req.params.file,
            file: fstream
        };


            var r = BASE.request.post({url: url+'test/service/uploadFile/', formData: formData}, function(err1, res1, body){
              console.log('new method err' + err1);
                console.log('new method' + res1);
                 clearInterval(tasktimeoutId);
                    tasktimeoutId = false;

                res.send(res1);
            });



var tasktimeoutId = null;
if(!tasktimeoutId){
                        tasktimeoutId = setInterval(function(){
    console.log('interval inside');
     interrupttable.findOne({ "filename": req.params.file }, function(err, thor) {
          if (thor!=null)
          {
              console.log('null inside');
              if(thor.status=='interrupt')
              {
                  console.log('interrupt');

        r.abort();              
                  r = null;
                  clearInterval(tasktimeoutId);
                    tasktimeoutId = false;
                  res.send("interrupted"); 
                  //return
  //next(err);

              }
          }
     });
        }, 1000);
}

    });

有没有办法以百分比检查文件进度。这样我就可以 在前端显示进度条。

【问题讨论】:

    标签: node.js upload progress-bar


    【解决方案1】:

    检查此回购:https://github.com/zeMirco/express-upload-progress。它应该有你要找的东西:)

    【讨论】:

      猜你喜欢
      • 2014-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-04
      • 2020-06-04
      • 2019-04-28
      相关资源
      最近更新 更多