Hy guys,
我有一些关于从galery使用插件phonegap / cordova获取格式图片的问题。在ios中,我不需要获取格式,但在android中我应该得到格式图片,例如.png / .jpg / .gif。
在我的代码中,我设置了:
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
不是带格式文件的结果文件,如何在option.filename
中获取格式文件?
答案 0 :(得分:0)
您需要检查mime类型
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");
});