0
votes

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

1
please provide the code snippet so we can help you - Amr.Ayoub
@Amr.Ayoub Done - pdm LVW
what is this.photoLibrary.saveImage function ? please post the code for it too - Amr.Ayoub
its a Plugin for saving images not a fuction github.com/terikon/cordova-plugin-photo-library - pdm LVW
you need to store the image on your firebase storage first . if you need an example on how to upload the picture then display it , let me know - Amr.Ayoub

1 Answers

1
votes

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();
  });

}