我试图创建一个脚本(Phonegap for Android)来从photogalery发送一个选定的图像,但它对我来说很难。
关注我的剧本:
function onCapturePhoto(imageURI) {
var uri = encodeURI("https://www.myserver.com/webservices/uploadFoto.php");
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType = "text/jpeg";
var ft = new FileTransfer();
ft.upload(imageURI, uri, win, fail, options);
function win(r) {
console.log("Code: = " + r.responseCode);
console.log("Response: = " + r.response);
console.log("Sent: = " + r.bytesSent);
}
function fail(error) {
console.log("An error has occurred: Code = " + error.code);
console.log("upload error source: " + error.source);
console.log("upload error target: " + error.target);
}
}
function getPhoto() {
navigator.camera.getPicture(onCapturePhoto, onFail, {
quality: 80,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
allowEdit : true,
targetWidth: 150,
encodingType: navigator.camera.EncodingType.JPEG
});
}
function onFail(message) {
alert('Failed because: ' + message);
}
林'收到以下错误:
发生错误:代码= 1
上传错误来源:file:///storage/emulated/0/Android/data/mobi.monaca.debugger/cache/.Pic.jpg
上传错误目标:https://www.myserver.com/webservices/uploadFoto.php
我正在使用Monaca Debugger。
答案 0 :(得分:2)
上传图片的代码错误:
options.mimeType = "text/jpeg";
将其更改为:
options.mimeType = "image/jpeg";
另一方面,Android 4.4的一些有用的选项代码
options.chunkedMode = false;
options.headers = {Connection: "close"};