0

this is my Code Please help me this is my code... My web service in .net how i pass image using java script and get in .net Web service and store in Folder and get it back again. i had tried this Min. 3 hours but i failed to get solution please help me...

    // Wait for Cordova to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // Cordova is ready
    //
    function onDeviceReady() {

        // Retrieve image file location from specified source
        navigator.camera.getPicture(uploadPhoto,
                                    function(message) { alert('get picture failed'); },
                                    { quality: 50, 
                                    destinationType: navigator.camera.DestinationType.FILE_URI,
                                    sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY }
                                    );

    }

    function uploadPhoto(imageURI) {
        var options = new FileUploadOptions();
        options.fileKey="file";
        options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
        options.mimeType="image/jpeg";

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

        options.params = params;

        var ft = new FileTransfer();
        alert(imageURI);
        ft.upload(imageURI, encodeURI("http://www.gameworld.co.in/useImage"), win, fail, options);
    }

    function win(r) {
        console.log("Code = " + r.responseCode);
        console.log("Response = " + r.response);
        console.log("Sent = " + r.bytesSent);
    }

    function fail(error) {
        alert("An error has occurred: Code = " + error.code);
        console.log("upload error source " + error.source);
        console.log("upload error target " + error.target);
    }

if you have other solution then please tell Me... Thanks

Nik
  • 25
  • 5
  • Try setting `options.chunkedMode = false;` – Davor Zlotrg Jul 31 '13 at 13:51
  • it Doesn't Work....What is meaning of code 1 error?? My Service is Called Or Not How can i check?? – Nik Jul 31 '13 at 14:00
  • Error code 1 is a FILE_NOT_FOUND_ERR. If you are using android, check this [answer](http://stackoverflow.com/questions/11754299/phonegap-android-unable-to-upload-image-using-filetransfer/14220608#14220608) – Davor Zlotrg Jul 31 '13 at 14:03

1 Answers1

0

You need to make use of function to get the actual path using
window.resolveLocalFileSystemURI(imguri, resolveOnSuccess, fsFail);

So your code would look like

var fileuri ="";
function uploadPhoto(imageURI) {
   window.resolveLocalFileSystemURI(imageURI, resolveOnSuccess, fsFail)
   var fileName = fileuri.substr(fileuri.lastIndexOf('/') + 1);
   options.fileName = fileName;

   // your remaining code 
}

function resolveOnSuccess(entry) {
   fileuri = entry.toURL();
   //console.log(fileuri);
}

function fsFail(message) {
  alert(message);
}
Divesh Salian
  • 1,457
  • 17
  • 30