Joshua Ohana Joshua Ohana - 2 years ago 387
iOS Question

How to access image from native URI (assets-library) in Cordova for iOS

I have a Cordova/PhoneGap app which uses the camera to capture a picture. I need to access this picture to send to my server.

For Android I simply use

$cordovaFile.readAsDataURL(cordova.file.dataDirectory, fileName)

However; on iOS the filename does not come back as such. My return value for iOS shows the path as


How can I access and read this image? I'd prefer to stick with $cordovaFile but just want to get it to work.

I am using CordovaCameraPreview plugin and the best I can get back from the picture taker handler seems to be something formed similar to:


How can I convert this to a filename and path that I can read with $cordovaFile? According to their documentation ( it looks like I need to use one of their paths for File System Layout. It works fine on Android using cordova.file.dataDirectory but can't figure out how to access on iOS

I've also tried using
but am getting undefined as my result.


I feel like I'm getting closer... using
window.resolveLocalFileSystemURL(path,resolveOnSuccess, resOnError);
I get more information

name: "assets-library"
fullPath: "/asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"
name: "asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"
nativeURL: "assets-library://asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"

It looks like I now need to use the fullPath but still can't figure out how to access with $cordovaFile

If I try to use
where is asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG I get a file not found error

Update 2

I have tried using every single File System Layout available at and receive the same File Not Found error on each one. Still no clue how to access a file in assets-library using $cordovaFile

Answer Source

I was struggling with a similar issue for a while, but I figured it out today. I also thought that the FileSystem APIs didn't work with assets-libary:// URIs -- but that is not the case.

You should be able to get access to the File object (as well as the actual image name) by using the following code:

resolveLocalFileSystemURL('assets-library://asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG', function(fileEntry) {
    fileEntry.file(function(file) {
        var reader = new FileReader();
        reader.onloadend = function(event) {
        console.log('Reading file: ' +;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download