Unable to copy/read url with "content://media/external/" on android


#1

I’m using the cordova-plugin-camera and cordova-plugin-file

My basic flow is

  1. using camera to select an image from gallery
  2. Select image is loaded into src of an tag
  3. Copy selected image in 2. when user chooses to save

This works fine in iOS but in android, I am unable to complete step 3
Basically, in step 2, I get a uri thats something like “content://media/external/images/media/1110” which is able to be displayed in img fine.
I am however unable to read/copy these uri using the file plugin functions.
Is there a way to convert the url to the real path? resolveLocalFileSystemURI doesn’t work for me

Alternately, I also tried writing the base64 data from the camera plugin as an image file but I get a broken image file when doing that although I have no problem display it as the “data:image/jpeg;base64,” in the camera example

$cordovaFile.writeFile(cordova.file.dataDirectory, “file.jpg”, imagedata, true)
.then(function (success) {
// success
var img = document.getElementById(‘camera_image’);
img.src = cordova.file.dataDirectory+“file.jpg”;
}, function (error) {
// error
});