在外部网站有一个输入(类型 - 文件)字段,我需要上传一个图像到这个输入。 在android中,我使用WebChromeClient和openFileChooser(ValueCallback uploadMsg,String acceptType,String capture)函数完成了此任务。 我不知道如何解决这个任务在phonegap /科尔多瓦。Phonegap /科尔多瓦上传图像文件
我的代码是:
function initialize() {
document.addEventListener('deviceready', onDeviceReady, false);
var ref = null;
}
function onDeviceReady() {
ref = window.open('http://example.com',
'_blank', 'location=no', 'EnableViewPortScale=yes');
ref.addEventListener('loadstop', LoadStop);
}
function LoadStop(event) {
if (event.url == 'http://example.com/Add') {
navigator.camera.getPicture(uploadPhoto, function(message) {
alert('get picture failed');
}, {
quality : 50,
destinationType : navigator.camera.DestinationType.FILE_URI,
sourceType : navigator.camera.PictureSourceType.PHOTOLIBRARY
});
}
}
function uploadPhoto(imageURI) {
console.log("imageURI----: " + imageURI);
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = "IMAG0475";
options.mimeType = "image/*";
var params = new Object();
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI,
encodeURI("http://example/Add"), 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);
}
检查此问题http://stackoverflow.com/questions/24139295/form-file-upload-phonegap/24142596#24142596 – Aravin 2014-09-22 10:43:26