Javascript PhoneGap上传照片:无法读取属性';文件';未定义的

Javascript PhoneGap上传照片:无法读取属性';文件';未定义的,javascript,mongodb,cordova,Javascript,Mongodb,Cordova,我正在尝试创建一个将照片上传到mongodb服务器的应用程序,下面是我的代码: upload = function (imageURI) { var ft = new FileTransfer(), options = new FileUploadOptions(); options.fileKey = "file"; options.fileName = 'filename.jpg'; Node at the se

我正在尝试创建一个将照片上传到mongodb服务器的应用程序,下面是我的代码:

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

        options.fileKey = "file";
        options.fileName = 'filename.jpg'; Node at the server side.
        options.mimeType = "image/jpeg";
        options.chunkedMode = false;
        options.params = { 
            "description": "Uploaded from my phone"
        };

        // alert(imageURI);
        // alert(serverURL);

        ft.upload(imageURI, serverURL + "/images",
            function (e) {
                getFeed();
            },
            function (e) {
                alert("Upload failed");
            }, options);
    }
在节点服务器端,这似乎是发生错误的地方:

    exports.addImage = function(req, res, next) {
    var file = req.files.file,
        filePath = file.path,
        lastIndex = filePath.lastIndexOf("/"),
        tmpFileName = filePath.substr(lastIndex + 1),
        image = req.body,
        images = db.collection('images');

    image.fileName = tmpFileName;
    console.log(tmpFileName);

    images.insert(image, function (err, result) {
        if (err) {
            console.log(err);
            return next(err);
        }
        res.json(image);
    });

};

因此,我有一个错误,无法读取未定义的属性“file”

我认为这是一个与您正在使用的express版本相关的错误。在早期版本的express(3.x)中,您应该包括:

app.use(express.methodOverride());
app.use(express.multipart())


因此,您可以访问req.files

什么是“服务器端的节点”?只添加了服务器端代码