Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DestinationType.NATIVE_URI returns content URI on Android. #404

Closed
sohrabtaee opened this issue Jan 8, 2019 · 9 comments
Closed

DestinationType.NATIVE_URI returns content URI on Android. #404

sohrabtaee opened this issue Jan 8, 2019 · 9 comments

Comments

@sohrabtaee
Copy link

DestinationType.NATIVE_URI returns content URI on Android which results in this error:
Not allowed to load local resource: content://com.android.providers.media.documents/document/image%3A6770

I had to use cordova-plugin-filepath to get the real native URI.
Stack overflow issue can be found here:
https://stackoverflow.com/questions/54088732/cordova-camera-plugin-not-allowed-to-load-local-resource-content

@jcesarmobile
Copy link
Member

Can you share your code?
Can you test with the dev code? I fixed a similar bug on #382, not sure if I covered your case

@sohrabtaee
Copy link
Author

<plugin name="cordova-plugin-camera" spec="^4.0.2" />
<engine name="android" spec="^7.0.0" />
      _chooseFromGallery() {
          navigator.camera.getPicture(
            this. _addPhoto.bind(this),
            this._onError, {
              sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
              destinationType: Camera.DestinationType.NATIVE_URL,
              encodingType: Camera.EncodingType.JPEG,
            });
        }

And this is the console output:
Not allowed to load local resource: content://com.android.providers.media.documents/document/image%3A6717

@hazems
Copy link
Member

hazems commented Feb 24, 2019

I checked latest code in master, and I found that NATIVE_URI option actually returns the right native URI that starts with file:// prefix.

@hazems
Copy link
Member

hazems commented Feb 24, 2019

@sohrabtaee another note, try to use Camera.DestinationType.NATIVE_URI instead of Camera.DestinationType.NATIVE_URL.

Destination type constants are defined as follows:

    DestinationType: {
        /** Return base64 encoded string. DATA_URL can be very memory intensive and cause app crashes or out of memory errors. Use FILE_URI or NATIVE_URI if possible */
        DATA_URL: 0,
        /** Return file uri (content://media/external/images/media/2 for Android) */
        FILE_URI: 1,
        /** Return native uri (eg. asset-library://... for iOS) */
        NATIVE_URI: 2
    },

@sohrabtaee
Copy link
Author

Hi @hazems

Thanks for taking the time to review this bug. Unfortunately, when I changed NATIVE_URL to NATIVE_URI still I get a broken image preview when I choose the photo from the photo library.

Note that it works fine when I take a photo using the camera.

@hazems
Copy link
Member

hazems commented Feb 26, 2019

This is weird, what is the device model and Android OS version does it has?

@sohrabtaee
Copy link
Author

I have tested on Galaxy S9 with both Android 8 and 9, but our customers have tested it with some other Android devices and the results were the same.

@tijlreynhout
Copy link

I also experience this issue...

@jcesarmobile
Copy link
Member

Closing as native_uri return type was removed on 5.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants