function getImage() {
Retrieve image file location from specified source
navigator.camera.MediaType.ALLMEDIA
navigator.camera.getPicture(uploadPhoto, function(message) {
alert('File Not Selected');
},{
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
mediaType: navigator.camera.MediaType.ALLMEDIA
}
);
}
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="uploaded";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "abc.php", win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
alert(r.response);
}
function fail(error) {
alert("An error has occurred: Code = " +error.code);
}
这可以通过 eclipse 在 android 模拟器上正常工作。当按下上传按钮并要求上传文件时;当在设备上运行 phonegap 创建 apk 文件时,它会失败,没有上传按钮工作。我还必须删除 phonegap.js。