Lucas Lucas - 1 year ago 202
Android Question

Cordova: Getting a file Uri from a content Uri

I implemented an app with Apache Cordova and I used $cordovaCamera plugin.
When the source type of $cordovaCamera is Camera.PictureSourceType.PHOTOLIBRARY the output is something like


and, when I use Camera.PictureSourceType.CAMERA I get


In my case the format "file://.." is more useful.

It is possible get the file URI from the content URI?

I found many answers to this questions but all solutions are for JAVA, not for Javascript.

Answer Source

I found the problem. I'm using Ionic and Ionic View for test in device.

When I tried the cordova-plugin-filepath it didn't work. But I found that the problem was that in Ionic View this plugin fails.

So, I wrote in a service this function:

// data is the return of $cordovaCamera.getPicture.

    getFilePath: function(data){ 
             var deferred = $q.defer();
             window.FilePath.resolveNativePath(data, function(result) {
                    deferred.resolve('file://' + result;);
                  }, function (error) {
                      throw new Error("");

             return deferred.promise;

to return the file URI that I needed it. Then, I installed the apk in the phone, and it works. Now, I can store an image obtained from the camera or gallery and upload to the server.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download