几天来,我一直试图弄清楚这一点。教程和文档都说了同样的话。
我想上传用户用相机拍摄的照片。但是,它不断地点击错误函数并说代码、源和目标为空。我的服务器永远不会被击中,而且似乎什么都没有。这是我的代码。
$(function() {
$('#camera').click(function() {
navigator.camera.getPicture(upload, function() {
alert('error');
},
{
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.CAMERA
});
});
var upload = function(image) {
console.log(image);
var options = new FileUploadOptions()
options.fileKey="file";
options.fileName=image.substr(image.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
console.log(image.substr(image.lastIndexOf('/')+1));
options.chunkedMode = true;
var ft = new FileTransfer();
ft.upload(image, encodeURI("http://mysite/upload.php"), 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);
}
});
配置文件
<access origin="*" />