You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by sencenan <gi...@git.apache.org> on 2015/12/03 07:04:00 UTC

[GitHub] cordova-plugin-camera pull request: [CB-10093][CB-9960][android] f...

GitHub user sencenan opened a pull request:

    https://github.com/apache/cordova-plugin-camera/pull/143

    [CB-10093][CB-9960][android] fix error resolving content uri to file url

    fixing: https://issues.apache.org/jira/browse/CB-10093
    
    Different app returns different uri. This is causing getRealPath() to return empty path.
    
    Fixed:
    
    - Gallery: content://media/external/images/media/117209
    - Google Photo: embeds a external image link inside another uri
    - Dropbox: old school file url
    
    Not fixed:
    
    - Google Drive: document uri, but has no document id, or the id cannot be used to query content resolver
    
    Notes:
    
    I have tested with: Gallery, Dropbox, Google Photo, and various file manager apps. However, this fix as is still does not address the problem with Google Drive.
    
    It seems to me that trying to get real file path from content uri seems to be a fundamentally flawed solution. It breaks the google sandbox between apps and this is going to get worse when more apps start to return the URL in "non-standard" formats.
    
    Use getContentResolver().openInputStream() and read the file directly could be a way forward, given that we are copying the image file already.
    
    For reference, I am using this following hack for my own branch to address problem with Google Drive:
    
    ```java
    private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
            // Some content: URIs do not map to file paths (e.g. picasa).
            String realPath = FileHelper.getRealPath(uri, this.cordova);
    
            //START OF HACK
            if (realPath.length() == 0) {
                String copiedFilePath = getTempDirectoryPath() + "/"
                        + System.currentTimeMillis() + ".copied."
                        + (this.encodingType == JPEG ? "jpg" : "png");
    
                InputStream fin = this.cordova.getActivity().getContentResolver().openInputStream(uri);
                OutputStream fout = new FileOutputStream(copiedFilePath);
    
                byte[] buf = new byte[1024 * 4];
                int len;
    
                while ((len = fin.read(buf)) > 0) {
                    fout.write(buf, 0, len);
                }
    
                fin.close();
                fout.close();
    
                realPath = copiedFilePath;
            }
            //END OF HACK
    
            // rest of ouputModifiedBitmap method
    }
    ```


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/sencenan/cordova-plugin-camera master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cordova-plugin-camera/pull/143.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #143
    
----
commit c09a8cf09b371c6071256444b81b18c10b3b70af
Author: sen.cenan@gmail.com <se...@gmail.com>
Date:   2015-11-30T20:18:03Z

    m: fix the crash when the uri passed into outputModifiedBitmap() is not a document URI

commit 05cdb0133f53fff109298ac2fb10a89026bb6462
Author: sencenan <se...@gmail.com>
Date:   2015-12-01T20:27:10Z

    m: response to code reivew on pull request 141

commit 83978ea3736168520eae2935ee0318d6fb9bc7c3
Author: sen.cenan@gmail.com <se...@gmail.com>
Date:   2015-12-03T05:49:47Z

    [CB-10093][CB-9960][android] fix error resolving content uri to file url

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-camera pull request: [CB-10093][CB-9960][android] f...

Posted by riknoll <gi...@git.apache.org>.
Github user riknoll commented on the pull request:

    https://github.com/apache/cordova-plugin-camera/pull/143#issuecomment-161744445
  
    @purplecabbage @sencenan I agree that getting the file path out of a content URI is becoming too convoluted to be sustainable. Getting the InputStream from the ContentResolver comes with it's own awkwardness as well, however, due to Android's [ExifInterface class](http://developer.android.com/reference/android/media/ExifInterface.html). We use that class to extract the EXIF data and preserve it as we modify the image (for quality, orientation, etc.). Unfortunately, it does not take in an InputSteam and so we would have to find/code a new EXIF reader or do something weird with writing the image twice (copy image to temp location -> read EXIF from temp image -> overwrite temp image with modified image -> return temp image URI). Thoughts?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-camera pull request #143: [CB-10093][CB-9960][android] fix er...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/cordova-plugin-camera/pull/143


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-camera pull request: [CB-10093][CB-9960][android] f...

Posted by sencenan <gi...@git.apache.org>.
Github user sencenan commented on the pull request:

    https://github.com/apache/cordova-plugin-camera/pull/143#issuecomment-161787751
  
    @riknoll that's my finding too with regard to ExifInterface class. I do think copying the image could be a viable solution like @purplecabbage said. Not entirely sure about the performance implications though.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-camera issue #143: [CB-10093][CB-9960][android] fix error res...

Posted by bgaillard <gi...@git.apache.org>.
Github user bgaillard commented on the issue:

    https://github.com/apache/cordova-plugin-camera/pull/143
  
    Hi, I think this Pull Request is very important, for now we cannot propose to the user of our applications to pick a picture. 
    
    Is the Cordova team planning to merge this PR soon ? 
    
    Thanks


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-camera pull request: [CB-10093][CB-9960][android] f...

Posted by purplecabbage <gi...@git.apache.org>.
Github user purplecabbage commented on the pull request:

    https://github.com/apache/cordova-plugin-camera/pull/143#issuecomment-161732640
  
    Copy the image to an app accessible temp location and return that url. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-plugin-camera issue #143: [CB-10093][CB-9960][android] fix error res...

Posted by infil00p <gi...@git.apache.org>.
Github user infil00p commented on the issue:

    https://github.com/apache/cordova-plugin-camera/pull/143
  
    This isn't going to be merged since we changed how we resolve file paths.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org