Я хочу выбрать форму андроидной галереи и загрузить изображение на сервер. Мой код работает правильно для приложений IOS. Но не получить изображение с телефона Android.Невозможно загрузить изображение, если оно выбрано из галереи на Android в телефоне
Внутри андроид приложение получать URL изображения показать, как это содержание
: //com.android.providers.media.documents/document/image%3A352
Что я должен сделать, чтобы получить правильное расширение изображения из галереи Android? Я использую приложение Hybird с Phonegap.
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
// Retrieve image file location from specified source
navigator.camera.getPicture(
uploadPhoto,
function(message) { alert('get picture failed'); },
{
quality : 100,
destinationType : navigator.camera.DestinationType.FILE_URI,
sourceType : navigator.camera.PictureSourceType.PHOTOLIBRARY
}
);
}
function uploadPhoto(imageURI) {
//alert(imageURI); return false;
//alert(imageURI);
var options = new FileUploadOptions();
options.fileKey="file";
//options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1)+'.png';
options.mimeType="image/jpeg";
var params = {};
params.value1 = "test";
params.value2 = "param";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.params = params;
options.chunkedMode = true; //this is important to send both data and files
alert(options.fileName);
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("file_upload.php"), win, fail, options);
}
function win(r) {
alert("Code = " + r.responseCode); //http response 200, means OK
alert("Response = " + r.response); //php uploader response (failed)
alert("Sent = " + r.bytesSent); //filesize
}
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);
}
Это полезно ... Спасибо – Avinash