簡體   English   中英

如何在node.js中使用formdata檢查文件上傳進度?

[英]how to check the progress of file uploading using formdata in node.js?

我想檢查在第三台服務器中文件上傳的百分比。 下面是我的控制器代碼。 將文件上傳到第三台服務器。

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);
}

    });

有什么方法可以檢查文件進度百分比。 這樣我就可以在前端顯示進度條。

檢查此倉庫: https : //github.com/zeMirco/express-upload-progress 它應該有您想要的東西:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM