var options = {
quality: 30,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
};
navigator.camera.getPicture(
function(imageURI) {
window.resolveLocalFileSystemURL(imageURI, function(fileEntry) {
console.log(fileEntry.toURI());
scope.$apply(function() {
ctrl.$setViewValue(fileEntry.fullPath);
});
}, function(err){
console.log(err);
});
},
function(err) {
console.log(err);
}, options
);
The imageURI returns '/media/external/images/media/11.
I wanted to get the real path but window.resolveLocalFileSystemURL only returns 'content://media/external/images/media/11'.
I'm trying to get something like '/mnt/sdcard/DCIM/camera/321321321.jpg'.
I just found the solution. The code change should be done within the plugin, not inside the javascript file.
First find the CameraLauncher.java
Add this function. This is the function that will convert '/media/external/images/media/' to realpath
public String getRealPathFromURI(Uri contentUri) {
String res = null;
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = cordova.getActivity().getContentResolver().query(contentUri, proj, null, null, null);
if(cursor.moveToFirst()){;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
res = cursor.getString(column_index);
}
cursor.close();
return res;
}
Then find this line. This is the one that returns imageURI on navigator.camera.getPicture(success())
if (this.targetHeight == -1 && this.targetWidth == -1 &&
(destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) {
this.callbackContext.success(uri.toString());
}
Change this line to
if (this.targetHeight == -1 && this.targetWidth == -1 &&
(destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) {
this.callbackContext.success(getRealPathFromURI(uri));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With