我正在尝试创建一个脚本(Android 的Phonegap)以从相册发送选定的图像,但这对我来说很难。
按照我的脚本:
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 调试器。