gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:14:35 26 4
gpt4 key购买 nike

引用:https://github.com/balderdashy/skipper/issues/49

适配器:船长网格

基本 Controller 代码:

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 中止( 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

我尝试在使用简单的上传 Controller (不是 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});
});

那么,有没有人看到这种情况发生,有什么解决方法吗?

最佳答案

此问题已在 skipper@0.5.4 和 skipper-disk@0.5.4 中解决

引用:https://github.com/balderdashy/skipper/issues/49

关于file-upload - 中止上传导致 Sails js/Skipper 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26896144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com