将图像从android应用程序上载到服务器

将图像从android应用程序上载到服务器,android,cordova,Android,Cordova,我尝试从android应用程序向服务器上传图像。我正在使用HTML5和phone gap。我正在使用WCF从android应用程序向远程服务器发送图像。当我尝试使用我的应用程序上传时,它会上传一个文件,但文件大小为0,所以里面什么都没有。(我的WCF工作正常,只是我知道问题出在我的android应用程序上) 这是我的上传代码: function uploadPicture() { // Get URI of picture to upload

我尝试从android应用程序向服务器上传图像。我正在使用HTML5和phone gap。我正在使用WCF从android应用程序向远程服务器发送图像。当我尝试使用我的应用程序上传时,它会上传一个文件,但文件大小为0,所以里面什么都没有。(我的WCF工作正常,只是我知道问题出在我的android应用程序上)

这是我的上传代码:

         function uploadPicture() {
        // Get URI of picture to upload  
        var img = document.getElementById('camera_image');
        var imageURI = img.src;

        if (!imageURI || (img.style.display == "none")) {

            document.getElementById('camera_status').innerHTML = "Take picture or select picture from library first.";
            return;
        }
        // Verify server has been entered  
        server = document.getElementById('serverUrl').value;
        if (server) {
            // Specify transfer options    
            var options = new FileUploadOptions();
            options.fileKey = "file";
            options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
            options.mimeType = "image/jpeg";
            options.chunkedMode = false;
            // Transfer picture to server
            var ft = new FileTransfer();
            ft.upload(imageURI, server, function(r) {
                document.getElementById('camera_status').innerHTML = "Upload successful: " + r.bytesSent + " bytes uploaded.";
            }, function(error) { document.getElementById('camera_status').innerHTML = "Upload failed: Code = " + error.code; },
                                                              options);

        } 
    }
尝试使用:

options.mimeType = "multipart/form-data";
并尝试设置一些参数。我正在发布一个适用于我的示例代码:

var imageFile=$("#largeImage").attr('src');

                        if(imageFile=="")
                            alert("No image to upload.");
                        else{
                        var ft,options;
                        options = new FileUploadOptions();
                        options.fileKey = "profile_image";
                        options.fileName=name;
                        options.mimeType = "multipart/form-data";

                          params = {
                            val1: "some value",
                            val2: "some other value"
                          };
                          options.params = params;
                        ft = new FileTransfer();
                        ft.upload(imageFile, uploadUrl, success, fail, options);
                        }
                    }

我正在使用java servlet处理上传的图像。

我也使用了这段代码,但它仍然在上传图像,但大小为0。