开发者

Phonegap Filetransfer API Not Work in SGS SII

开发者 https://www.devze.com 2023-04-09 13:44 出处:网络
i\'m newbie on phonegap, I am just trying transfer a file to my server via phonegap 1.0 Filetransfer API and work on android emulator Android 2.3.3 (API level 10) but don\'t work with real device ( sa

i'm newbie on phonegap, I am just trying transfer a file to my server via phonegap 1.0 Filetransfer API and work on android emulator Android 2.3.3 (API level 10) but don't work with real device ( samsung galaxy sII) bellow my code :

document.addEventListener("deviceready",onDeviceReady,false);

function onDeviceReady() {
    pictureSource=navigator.camera.PictureSourceType;
    destinationType=navigator.camera.DestinationType;
}


function capturePhoto() {
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { 
       quality: 30, destinationType: destinationType.FILE_URI 
    });
}

function onPhotoURISuccess(imageURI) {
    $(".loading").show()
    var doit = $('a#sendkamera').attr('rel');
    var smallImage = document.getElementById('smallImage');
    smallImage.style.display = 'block';
    smallImage.src = imageURI;

    var options = new FileUploadOptions();
    options.fileKey="file";
//options.fileName="newfile.txt";
    options.mimeType="image/jpeg";

    var params = new Object();
    params.value1 = "test";
    params.value2 = "param"; 
    options.params = params;
    var ft = new FileTransfer();
    ft.upload(imageURI, "http://api.byur.in/android/upload/", win, fail, options);
}

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

function fail(error) {
    alert("An error has occurred: Code = " = error.code);
}

I don't understand, why this code can be successful with alert status code = -1, but when I look at the log server, I don't see the request.

i try upload file via ajax and work on emulator but dont work with real device with error message status code = 0. bellow my code

function capturePhoto() {
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 30 });
}

function errorCallback(xhr, textStatus, errorThrown) {
    navigator.notification.bee开发者_开发技巧p(3);
    alert(textStatus + errorThrown + ' coba lagi di waktu mendatang');
    alert(xhr.responseText);    
}


function successIMG(imageData) {
    var doit = $('a#sendkamera').attr('rel');
    $('.loading').show(); 
    var data = {image: imageData};
    var url = 'http://api.byur.in'+doit;
    $.ajax({url:url, type:'POST', data:data, success:function(data){
        $('.loading').hide(); alert('sukses'); },error: errorCallback });
}

I am not sure where I am going wrong. What can I do to fix this problem?

thanks for your reply

0

精彩评论

暂无评论...
验证码 换一张
取 消