Cordova 3.5.0 FileTransfer + NodeJS(multipart / form-data)上传问题

时间:2014-07-24 22:52:21

标签: node.js file cordova multipartform-data transfer

Cordova 3.5.0,文件传输插件Android js文件。

  var ft = new FileTransfer();
  var options = new FileUploadOptions();
  options.fileKey="files";
  options.fileName=path.substr(path.lastIndexOf('/')+1);
  options.mimeType="video/mp4";
  options.headers = {Connection: "close"};
  options.chunkedMode = false;
  options.httpMethod = 'POST';

  ft.onprogress = function(progressEvent) {
    if (progressEvent.lengthComputable) {
      loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
    } else {
      loadingStatus.increment();
    }
    colsole.log(progressEvent.loaded / progressEvent.total);
  };

  ft.upload(path, uri, win, fail, options);

Node.JS服务器

app.post('/upload', function(req, res) {
    console.log('upload req:'+util.inspect(req.files));
}

Console.log返回" undefined"对于req.files。适用于原生Android程序和网络上传。

1 个答案:

答案 0 :(得分:0)

如果您正在使用ExpressJ(它看起来像您正在使用),那么您需要安装Multer中间件来处理多部分数据。

https://github.com/expressjs/multer