简体   繁体   中英

How to get Format Image from cordova/phonegap used getPicture From Gallery in Android?

Hy guys,

i have some question about get format picture from galery used plugin phonegap/cordova. in ios, i do not have to get format, but in android i should getting format picture, example .png / .jpg / .gif.

In my code I set :

 navigator.camera.getPicture(uploadPhoto, function(message) { alert('get picture failed'); }, { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM }); } function uploadPhoto(imageURI) { var options = new FileUploadOptions(); options.fileKey = "file"; if (device.platform == "Android" || device.platform == "android") { options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1); } options.mimeType = "image/jpg"; var user = Storage.getObject("user"); var params = new Object(); options.params = { user_id: parseInt(user.id) } options.chunkedMode = false; var ft = new FileTransfer(); ft.upload(imageURI, "http://www.exampl.com/app/upload-receiptPhotoLibrary", win, fail, options); } 

option.filename not result file with format file, how to get format file in option.filename ?

You need to check the mime type

var sFile = new MediaFile("some.jpg", "file:///mnt/sdcard/some.jpg");
console.log("file path = " + sFile.fullPath);
sFile.getFormatData(function(metadata) {
    console.log("mimeType = " + metadata.type);
}, function() {
    console.log("fail");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM