1

i got a very strange behavior when i tried to load image from cdvfile://

case 1: i tried to load image with cordova camera.getPicture with options:

{
  destinationType: Camera.DestinationType.NATIVE_URI, 
  sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM, 
  correctOrientation: true
}

so in this case, with correctOrientation: true, cordova made a copy of the original file and stored it in the app cache folder and in the callback i got the cache file path. Then i converted it into cdvfile, it worked perfectly.

case 2: in case 1, i'm unhappy, because i want the original file path, so i can save it and reload it when i want. so i changed a bit the code: the fastest way is removing the option correctOrientation: true so i get the originale file path, then with window.resolveLocalFileSystemURL(same method in case 1), i get the cdvfile, i set it to image.src and bam:

Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME

so working perfectly with cached file:

file uri: file:///storage/emulated/0/Android/data/{app_id}/cache/IMG_20170119_091504.jpg?1484813705413

converted file url: cdvfile://localhost/cache-external/IMG_20170119_091504.jpg

not working with original file:

file uri: content://com.android.providers.media.documents/document/image%3A91315

converted into cdvfile: cdvfile://localhost/content/com.android.providers.media.documents/document/image%3A91316:1

i'm really confused... any ideas to solve this error?

im using:

  • angular@1.6.1
  • meteor@1.4.2.3
  • bundled cordova-android@5.2.2
  • cordova-plugin-camera@2.2.0
  • cordova-plugin-file@4.2.0
  • nexus7@6.0.1
Haozhe Yu
  • 39
  • 6
  • why do you need a cdvfile? – Bala Abhinav Jan 19 '17 at 09:54
  • @BalaAbhinav i need the file path, so the app can reload the image next time i open it, or when i load a new project. i'm dont want to use data_url, its heavy to handle – Haozhe Yu Jan 19 '17 at 16:32
  • Check this out. It addresses all the issues that you have posted : http://stackoverflow.com/questions/10335563/capturing-and-storing-a-picture-taken-with-the-camera-into-a-local-database-ph – Bala Abhinav Jan 20 '17 at 07:36
  • yeah, the concept is same, but my problem is that i cannot load the image from `cdvfile://` scheme when the image is locate in `content://com.android.providers.media.documents/document` ... it might be the uri decoding issue like in [this case](http://stackoverflow.com/questions/20638932/unable-to-load-image-when-selected-from-the-gallery-on-android-4-4-kitkat-usin) – Haozhe Yu Jan 20 '17 at 21:06
  • 1
    well, i changed the approach to [that](http://stackoverflow.com/questions/10335563/capturing-and-storing-a-picture-taken-with-the-camera-into-a-local-database-ph) you have suggested, it's the best way – Haozhe Yu Jan 20 '17 at 22:08

0 Answers0