typescript - Unable to set img src from cordova file in Ionic -


i'm using cordova-plugin-file-transfer , cordova-plugin-file download user avatars , display them locally in app. i'm fetching images , storing them in file.datadirectory according to: https://ionicframework.com/docs/native/file-transfer/ . when check file in directory says exists...however when try set absolute path of file <img> tag see nothing. i'm pulling in path dynamically when hardcode it...nothing.

code saving, loading avatars:

saveavatar() {     var downloadurl = this.user.avatar + "?type=small&sz=75";      console.log("downloading avatar from: " + downloadurl);     console.log("storing file to: " + this.file.datadirectory + this.user.id + '/avatar.jpg');       this.filetransfer.download(downloadurl, this.file.datadirectory + this.user.id + '/avatar.jpg')     .then((entry) => {         console.log('~~~~~ download complete: ' + entry.tourl());     }, (error) => {         console.log('unable download avatar: ' + error);     }); }  loadavatar() {     var userdir = this.file.datadirectory + this.user.id;     var filename = 'avatar.jpg';      this.file.resolvedirectoryurl(userdir)     .then((directoryentry: directoryentry) => {         console.log("dir resolved: " + directoryentry.isdirectory);          this.file.getfile(directoryentry, filename, { create: false })         .then(file => {             console.log("file found: " + file.tourl());             this.avatars[this.user.id] = file.tourl();         })         .catch(err => console.log('unable load avatar: ' + err));     })     .catch(err => console.log('unable resolve directory entry: ' + json.stringify(err))); } 

the absolute paths of stored images such:

file:///data/user/0/package_name_here/files/1/avatar.jpg 

or when trying on external storage:

file:///storage/emulated/0/android/package_name_here/files/1/avatar.jpg 

any helps appreciated!

figured out problem. though running on android device, running live in ionic doesn't work cordova plugins. instead of doing ionic cordova run android -l -c have run ionic cordova android.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -