pdm LVW
pdm LVW

Reputation: 149

Saving Image Using firebase Url to gallery ionic 3

I'm developing ionic 3 app which can download images from firebase. images can download successfully by giving the url.

By giving a regular link to image like this

the image will be download.This is working.

but if i give a firebase storage url like https://firebasestorage.googleapis.com/v0/b/myapp.appspot.com/o/1.jpg?alt=media&token=xxx

it won't download.In console i can see the image path and when i click it will open in browser.but when i run it on android it will not download.

How can i fix this?

my code for the download

download()
{
 var url =  'https://firebasestorage.googleapis.com/v0/b/myapp.appspot.com/o/1.jpg?alt=media&token=ea450d47-b12c-4bcc-9e35-c2aba22bc155'
      var album = 'MyAppName';
      this.photoLibrary.saveImage(url,album).then((entry=>{
        console.log('download complete: ' + entry.photoURL);
        this.presentToast('download complete:' + entry.photoURL);
      }),
      (error) => {
        // handle error
        this.presentToast(error);
        this.loader.dismiss();
      });
}

I just found that tokens are downloading but not images

Upvotes: 0

Views: 1273

Answers (1)

Amr.Ayoub
Amr.Ayoub

Reputation: 728

First you need to store your images on firebase ,change "MyImage" to your firebase storage. then get the url and save the image on album by calling saveToAlbum function

getImage(image: string) {
     try {
         this.firebase.storage().ref().child("/myImages/" + image).getDownloadURL().then(function(url) {
             this.saveToAlbum(url)
         });
     } catch (e) {
         console.log(e);
     }
 }


saveToAlbum(url){
let album = 'MyAppName';
  this.photoLibrary.saveImage(url,album).then((entry=>{
    console.log('download complete: ' + entry.photoURL);
    this.presentToast('download complete:' + entry.photoURL);
  }),
  (error) => {
    // handle error
    this.presentToast(error);
    this.loader.dismiss();
  });

}

Upvotes: 1

Related Questions