0

I am using PhoneGap to develop a mobile that should be able to take and upload a picture. Nevertheless I do not get any feedback from my upload script (neither 'Success' or 'Fail') and the picture is not uploaded on the server when the target URL begins with httpS (that works well with http). Nevertheless scripts I use come from the various examples I found on Stackoverflow.

Below is the code I use:

    $('#mr_take_picture').click(function(){
    $('#mr_take_picture').prop('disabled', true);

    navigator.camera.getPicture(uploadPhoto,
                            function(message) { alert('get picture failed'); },
                            { quality: 50, 
                            destinationType: navigator.camera.DestinationType.FILE_URI }
                            );
    $('#mr_take_picture').prop('disabled', false);

});

function uploadPhoto(imageURI) {
    var options = new FileUploadOptions();

    options.fileKey="file";
    options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
    options.mimeType="image/jpeg";
    options.headers = { Connection: "close" }
    options.chunkedMode = false;

    var params = new Object();
    params.value1 = "test";
    params.value2 = "param";

    options.params = params;

    var ft = new FileTransfer();
    console.log('transfer starting');
    ft.upload(imageURI, encodeURI('https://www.my-server.com/files/test.php'), win, fail, options);
    console.log('transfer finished');
}

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

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

Below is the file test.php

<?php $new_image_name = "YEAH.jpg"; move_uploaded_file($_FILES["file"]["tmp_name"], "/var/www/html/files/".$new_image_name); ?>

Below is what I can see in the phonegap console when I try to take a picture and upload it:

[phonegap] 200 /__api__/autoreload
[phonegap] [console.log] transfer starting
[phonegap] 200 /socket.io/?EIO=2&transport=polling&t=1431336989085-21&sid=_Bw59PxBVBjKSpAaAAAK
[phonegap] 200 /__api__/autoreload
[phonegap] [console.log] transfer finished
[phonegap] 200 /socket.io/?EIO=2&transport=polling&t=1431336989220-22&sid=_Bw59PxBVBjKSpAaAAAK
[phonegap] 200 /__api__/autoreload

As you can see it appears that the functions win and fail are never executed.. Where could the problem come from?

Thanks!

jww
  • 97,681
  • 90
  • 411
  • 885
Pierre
  • 1,044
  • 15
  • 27
  • Actually, it works well with http, not with httpS... I added the parameter TRUE to the ft.upload() method but this still does not work. How to deal with that? – Pierre May 16 '15 at 14:34
  • One more precision: the SSL/TLS certificate is not "Self-signed" and use SHA-1. – Pierre May 16 '15 at 14:36

0 Answers0