NodeJs上传文件错误:请求已中止

时间:2014-04-11 23:00:21

标签: node.js cordova file-upload formidable

我试图从我使用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。 我能做什么??

1 个答案:

答案 0 :(得分:0)

您使用的是哪个版本的快递?

表单多部分中间件在快递4中删除

如果是这样的话,请尝试使用:https://github.com/mscdex/connect-busboy

相关问题