0

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

6
  • please provide the code snippet so we can help you Commented Jan 2, 2018 at 9:38
  • @Amr.Ayoub Done Commented Jan 2, 2018 at 9:45
  • what is this.photoLibrary.saveImage function ? please post the code for it too Commented Jan 2, 2018 at 9:46
  • its a Plugin for saving images not a fuction github.com/terikon/cordova-plugin-photo-library Commented Jan 2, 2018 at 9:47
  • 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 Commented Jan 2, 2018 at 9:53

1 Answer 1

1

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

}

Sign up to request clarification or add additional context in comments.

1 Comment

Thank You this is also do the same thing in a properway. I found the problem it will download the whole url as a file.I manually clear the file name without the image name now its showing. Is there any way to clearout the token things in firebase??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.