没有关于文件上传的反馈

时间:2015-05-11 10:15:15

标签: cordova ssl https file-transfer

我正在使用PhoneGap开发一款能够拍摄并上传照片的手机。然而,我没有从我的上传脚本(“成功”或“失败”)获得任何反馈,并且当目标URL以http S 开头时,图片未上传到服务器上(适用于HTTP)。然而,我使用的脚本来自我在Stackoverflow上找到的各种示例。

以下是我使用的代码:

    $('#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));
}

以下是test.php文件

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

当我尝试拍照并上传时,我可以在phonegap控制台中看到以下内容:

[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

正如您所看到的那样,似乎永远不会执行函数win和fail。问题可能来自哪里?

谢谢!

0 个答案:

没有答案