使用cordova将params发送到节点服务器

时间:2014-07-09 10:21:47

标签: node.js cordova

我尝试上传文件并在同一请求中发送params,但是我在文件传输方面可能会遇到问题,但是我在服务器端遇到问题,req.body总是空的我使用了强大的功能模块

这是客户端

        upload = function (imageURI) {
        var ft = new FileTransfer(),
            options = new FileUploadOptions();

        options.fileKey = "file";
        options.fileName = 'filename.jpg'; // We will use the name auto-generated by Node at the server side.
        options.mimeType = "image/jpeg";
        options.chunkedMode = false;


        var params = {};
        params.value1 = "test";
        params.value2 = "param";

        options.params = params;


        alert(imageURI);
        ft.upload(imageURI, serverURL + "/upload",
            function (e) {
                getFeed();
            },
            function (e) {
                alert("Upload failed");
            }, options);
    },

这是服务器端

  

var form = new formidable.IncomingForm();

 form.parse(req, function(error, fields, files) {
      console.log(req.body.value1);


console.log("Traitement terminé");

1 个答案:

答案 0 :(得分:1)

我发现了我必须更换的问题

  

的console.log(req.body.value1);

通过

  

的console.log(fields.value1);