Ref: https://github.com/balderdashy/skipper/issues/49
Adapter: skipper-gridfs
Basic controller code:
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 {
I have a jQuery-File-Upload client ( https://blueimp.github.io/jQuery-File-Upload/ ) impementing the "cancel" procedure by using jqXHR abort described here (https://github.com/blueimp/jQuery-File-Upload/wiki/API ):
$('button.cancel').click(function (e) { jqXHR.abort(); });
After the client aborts, the server crashes with the following message:
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)
I've used try/catch but it didn't work, the server crashes anyway.
I am not sure if this is a Skipper issue or a Multiparty issue -- my knowledge stops here ( 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); } }
At first I thought this was the way the jqXHR request was aborted, but it seems to be a generic Skipper issue on aborted uploads, since the simple act of closing the tab during an upload will crash the server (different message):
_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
I have tried aborting the upload by closing the tab while using a simple upload controller (not Skipper) and there is no crash:
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}); });
So, did anybody see this happening and is there any workaround?