0

这是我的代码 请帮助我这是我的代码... 我在 .net 中的 Web 服务如何使用 java 脚本传递图像并进入 .net Web 服务并存储在文件夹中并再次取回。我试过这个分钟。3小时,但我没有得到解决方案,请帮助我......

    // 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);
    }

如果您有其他解决方案,请告诉我...谢谢

4

1 回答 1

0

您需要使用函数来获取实际路径
window.resolveLocalFileSystemURI(imguri, resolveOnSuccess, fsFail);

所以你的代码看起来像

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);
}
于 2013-08-01T08:33:53.197 回答