외부 웹 사이트에 입력 (유형 - 파일) 입력란이 있으며이 입력에 이미지를 업로드해야합니다. android에서이 작업을 WebChromeClient 및 openFileChooser (ValueCallback uploadMsg, String acceptType, String capture) 함수로 수행했습니다. phonegap/cordova에서이 작업을 해결하는 방법을 모르겠습니다.Phonegap/Cordova 업로드 이미지 파일
내 코드는 다음과 같습니다 기본 코르도바 응용 프로그램
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