idleMind
idleMind

Reputation: 161

file:/// path image from SD-Card not showing in ionic cordova

I have downloaded image using $cordovaFileTransfer plugin and stored them in cordova.file.externalDirectory.. stored its path in sqlite local database.

When I set that image's path in image "ng-src" using ng-repeat.. images are not showing up.. I can see 'em in chrome "Inspect Element" that the path is actually having image in there, but somehow its not previewing.

image path which I am getting is something like this: file:///storage/sdcard0/appify/imgs/DSC_0124_1443159471.jpg

but, image not rendering

Any help on this?

Thank you

Upvotes: 2

Views: 2995

Answers (1)

getglad
getglad

Reputation: 2562

So a couple of things to look at:

  1. https://github.com/apache/cordova-plugin-file#where-to-store-files

You may want to look into cordova.file.externalDataDirectory

Also, the plugin doc reads:

For backwards compatibility, the resolveLocalFileSystemURL() method will accept a device-absolute-path, and will return an Entry object corresponding to it, as long as that file exists within either the TEMPORARY or PERSISTENT filesystems.

This has particularly been an issue with the File-Transfer plugin, which previously used device-absolute-paths (and can still accept them). It has been updated to work correctly with FileSystem URLs, so replacing entry.fullPath with entry.toURL() should resolve any issues getting that plugin to work with files on the device.

  1. https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL

Have you tried reading the file in?

window.resolveLocalFileSystemURL(imageData, function(fileEntry) {
   fileEntry.file(function(file) {
      var reader = new FileReader();
      reader.onloadend = function(evt) {
         // set source here using result
      }
      reader.readAsDataURL(file);
   });
});

Upvotes: 2

Related Questions