Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-9891

Inconsistent URI encoding causing permission errors on android

    XMLWordPrintableJSON

Details

    Description

      Using the camera plugin to get a picture from the photo library returns an encoded URI. If you then call resolveLocalFileSystemURI the fileEntry object returned contains the decoded path component of the URI. This path property is used in the toInternalURL function which means it's also decoded. Because Android gave us permission to the encoded URI, but not the decoded URI, attempting to access the decoded URI results in a permission error.

      document.getElementById("myButton").addEventListener("click", function(){
                  navigator.camera.getPicture(function(uri){
                      console.log(uri); //content://com.android.providers.media.documents/document/image%3A27         
      		window.resolveLocalFileSystemURI(uri, function(fileEntry){
                          console.log(fileEntry.toInternalURL()); //cdvfile://localhost/content/com.android.providers.media.documents/document/image:27                                                                              
                          fileEntry.file(function(){alert("success");}, function(){alert("fail");});
                      },function(error){
                          // resolved by pulling in PR 119
                          alert("Fail resolveFileSystemURI code: " + error.code);
                      });
                  }, null, {sourceType: 0, allowEdit: false});
              });
      

      I feel like something must be wrong in one of the plugins, but I'm not sure where.

      One possible fix is calling uri.getEncodedPath() instead of uri.getPath in LocalFileSystemURL.parse and then removing the call to encodeURI() from FileSystem.js, but I'm not sure if this is the right strategy. Example

      Attachments

        Issue Links

          Activity

            People

              jasongin Jason Ginchereau
              cjpearson Connor Pearson
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: