中止上传导致Sails js / Skipper崩溃

时间:2014-11-12 20:41:29

标签: file-upload sails.js skipper

参考:https://github.com/balderdashy/skipper/issues/49

适配器:skipper-gridfs

基本控制器代码:

req.file('fileTest')
        .upload({

        // You can apply a file upload limit (in bytes)
        maxBytes: maxUpload,
        adapter: require('skipper-gridfs'),
        uri: bucketConnect,
        saveAs : function (__newFileStream,cb) {
            cb(null, __newFileStream.filename);
        }

    }, function whenDone(err, uploadedFiles) {
        if (err) {
            var error = {  "status": 500, "error" : err };
            return res.serverError(error);
        }else {

我有一个jQuery-File-Upload客户端(https://blueimp.github.io/jQuery-File-Upload/)通过使用此处描述的jqXHR abort(https://github.com/blueimp/jQuery-File-Upload/wiki/API)来强制执行“取消”过程:

$('button.cancel').click(function (e) {
    jqXHR.abort();
});

客户端中止后,服务器崩溃并显示以下消息:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Request aborted
    at IncomingMessage.onReqAborted (.../node_modules/sails/node_modules/skipper/node_modules/multiparty/index.js:175:17)
    at IncomingMessage.EventEmitter.emit (events.js:92:17)
    at abortIncoming (http.js:1911:11)
    at Socket.serverSocketCloseListener (http.js:1923:5)
    at Socket.EventEmitter.emit (events.js:117:20)
    at TCP.close (net.js:466:12)

我已经使用过try / catch但它没有用,无论如何服务器都崩溃了。

我不确定这是一个船长问题还是多党派问题 - 我的知识在此停止(https://github.com/andrewrk/node-multiparty/blob/master/index.js):

function onReqAborted() {
    waitend = false;
    self.emit('aborted');
    handleError(new Error("Request aborted"));
  }

  function onReqEnd() {
    waitend = false;
  }

  function handleError(err) {
    var first = !self.error;
    if (first) {
      self.error = err;
      req.removeListener('aborted', onReqAborted);
      req.removeListener('end', onReqEnd);
      if (self.destStream) {
        self.destStream.emit('error', err);
      }
    }

    cleanupOpenFiles(self);

    if (first) {
      self.emit('error', err);
    }
  }

起初我认为这是jqXHR请求中止的方式,但它似乎是关于中止上传的通用Skipper问题,因为在上传过程中关闭选项卡的简单操作会使服务器崩溃(不同的消息):

_stream_writable.js:233
    cb(er);
    ^
TypeError: object is not a function
    at onwriteError (_stream_writable.js:233:5)
    at onwrite (_stream_writable.js:253:5)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at Writable.<anonymous> (.../node_modules/skipper-gridfs/index.js:179:25)
    at Writable.g (events.js:180:16)
    at Writable.EventEmitter.emit (events.js:117:20)
    at PassThrough.<anonymous> (.../node_modules/skipper-gridfs/index.js:194:36)
    at PassThrough.g (events.js:180:16)
    at PassThrough.EventEmitter.emit (events.js:117:20)
    at .../node_modules/sails/node_modules/skipper/standalone/Upstream/prototype.fatalIncomingError.js:55:17

我尝试在使用简单的上传控制器(不是Skipper)时关闭标签来中止上传,并且没有崩溃:

var uploadFile = req.file('fileTest');
    console.log(uploadFile);

    uploadFile.upload(function onUploadComplete (err, files) {                // Files will be uploaded to .tmp/uploads

        if (err) return res.serverError(err);                              // IF ERROR Return and send 500 error with error

        console.log(files);
        res.json({status:200,file:files});
    });

那么,有没有人看到这种情况发生了,有没有解决办法?

2 个答案:

答案 0 :(得分:1)

此问题已在skipper@0.5.4和skipper-disk@0.5.4

中解决

参考:https://github.com/balderdashy/skipper/issues/49

答案 1 :(得分:1)

还有一个问题在skipper-gridfs@0.5.3

链接:https://github.com/willhuang85/skipper-gridfs/issues/20