【问题标题】:NodeJs Upload file Error: Request AbortedNodeJs上传文件错误:请求中止
【发布时间】:2014-05-26 06:41:37
【问题描述】:

我正在尝试从使用 Cordova (Phonegap) 开发的应用程序上传文件(图片),但我总是获得Error: Request Aborted。一开始我用的是fs.readFile(),这是我读到的第一件事,但现在我用Fomidable,但错误是一样的:

错误

Error: Request aborted
    at IncomingMessage.onReqAborted (../XAMPP/xamppfiles/htdocs/nodeyag/node_modules/express/node_modules/connect/node_modules/multiparty/index.js:131:17)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at abortIncoming (http.js:1912:11)
    at Socket.serverSocketCloseListener (http.js:1924:5)
    at Socket.EventEmitter.emit (events.js:117:20)
    at TCP.close (net.js:466:12)

/picUpload

var form = new formidable.IncomingForm();

form.parse(req,function(err,fields,files) {
    if(err) console.log(err);
    console.log(files);
});

form.on('end',function(fields,files) {
    // temporary location of the uploaded file
    var tempPath = this.openedFiles[0].path;
    // filename of the uploaded file
    var fileName = this.openedFiles[0].name,
    newPath = config.uploadPicsDir + '/docs/';

    var file = { tempPath: tempPath, fileName: fileName };
        console.log(file);

        fs.copy(tempPath, newPath + 'picture.jpg' , function(err) {
            if(err) return next(err);

            console.log("file success!");

            res.send('Ok');
       });//end of copy()
});

为了复制文件,我使用了 fs-extra 模块。 我能做些什么??

【问题讨论】:

  • 您找到解决方案了吗?我也遇到了同样的错误。

标签: node.js cordova file-upload formidable


【解决方案1】:

你用的是哪个版本的快递?

在 express 4 中移除了表单多部分中间件

如果是这种情况,请尝试使用:https://github.com/mscdex/connect-busboy

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-28
    • 2014-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多