Sails js,skipper:如果上传被取消或请求中止,则不会删除文件-

时间:2019-07-17 11:55:57

标签: node.js sails.js sails-skipper

我是Sails JS和船长磁盘文件上传的新手。如果上传被取消或请求中止,则该过程不会释放部分上传的文件。

我尝试上传1 GB的文件。 上传我的根磁盘之前,可用大小为81GB 请求中止问题后,我已删除文件。但是磁盘可用大小仍显示为80GB。 如果重新启动服务器,则磁盘可用大小将增加到1GB。

upload: function  (req, res) {

      var tmp_file_name = "test1.gz"
      console.log("Upload Files: " + tmp_file_name)
      req.file('avatar').upload({
        maxBytes: 10000000000,
        saveAs: tmp_file_name
    },function onUploadComplete(err, uploadedFiles) {        
        if (err) {          
          var file_uploaded = process.cwd() + "/.tmp/uploads/" + tmp_file_name;
          console.log("Deleting Files: " + file_uploaded)
          deleteFile(file_uploaded);
          return res.negotiate(err) //res.serverError(err);
        } else {
        return res.json({
          message: uploadedFiles.length + ' file(s) uploaded successfully!',
          files: uploadedFiles
        });
      }})
}

遇到下述错误

error: Sending 500 ("Server Error") response:
Error: Request aborted
at IncomingMessage.onReqAborted (/home/chandan/Desktop/work/nodejs/Beginnersprojetc/node_modules/multiparty/index.js:183:17)
at emitNone (events.js:106:13)
at IncomingMessage.emit (events.js:208:7)
at abortIncoming (_http_server.js:424:9)
at socketOnClose (_http_server.js:418:3)
at emitOne (events.js:121:20)
at Socket.emit (events.js:211:7)
at TCP._handle.close [as _onclose] (net.js:567:12)

删除文件lsof命令后,该命令显示进程正在保存部分上载的文件。

node 1988 chandan 19w REG 8,1 296318290 4719334 /home/chandan/Desktop/work/nodejs/Beginnersprojetc/.tmp/uploads/test1.gz (deleted)
node 1988 1989 chandan 19w REG 8,1 296318290 4719334 /home/chandan/Desktop/work/nodejs/Beginnersprojetc/.tmp/uploads/test1.gz (deleted)
node 1988 1990 chandan 19w REG 8,1 296318290 4719334 /home/chandan/Desktop/work/nodejs/Beginnersprojetc/.tmp/uploads/test1.gz (deleted)
node 1988 1991 chandan 19w REG 8,1 296318290 4719334 /home/chandan/Desktop/work/nodejs/Beginnersprojetc/.tmp/uploads/test1.gz (deleted)
node 1988 1992 chandan 19w REG 8,1 296318290 4719334 /home/chandan/Desktop/work/nodejs/Beginnersprojetc/.tmp/uploads/test1.gz (deleted)
node 1988 1993 chandan 19w REG 8,1 296318290 4719334 /home/chandan/Desktop/work/nodejs/Beginnersprojetc/.tmp/uploads/test1.gz (deleted)
node 1988 2000 chandan 19w REG 8,1 296318290 4719334 /home/chandan/Desktop/work/nodejs/Beginnersprojetc/.tmp/uploads/test1.gz (deleted)
node 1988 2001 chandan 19w REG 8,1 296318290 4719334 /home/chandan/Desktop/work/nodejs/Beginnersprojetc/.tmp/uploads/test1.gz (deleted)
node 1988 2002 chandan 19w REG 8,1 296318290 4719334 /home/chandan/Desktop/work/nodejs/Beginnersprojetc/.tmp/uploads/test1.gz (deleted)
node 1988 2003 chandan 19w REG 8,1 296318290 4719334 /home/chandan/Desktop/work/nodejs/Beginnersprojetc/.tmp/uploads/test1.gz (deleted)

0 个答案:

没有答案