I can't display an image in app from firebase storage using the image url

Viewed 503

I want to show an Image which I have successful stored into firebase storage. I got the user to pick an image from gallery and saved it on the database. I then saved the URL link in the real-time database, which I thought I could just bind to the image.source however this does not work. I have also tried copying the link from the firebase console straight into XAML that didn't work. I also tried downloading the image onto the phone(code below) how ever this doesn't work. I can't find any tutorials anywhere for displaying images from firebase for Xamarin forms. I'm a bit stuck here.

 public void LoadImages(string imgurl)
     {
         var webClient = new WebClient();
         byte[] imgBytes = webClient.DownloadData(imgurl);
         //string img = Convert.ToBase64String(imgBytes);
         petimage.Source = ImageSource.FromStream(() => new MemoryStream(imgBytes));                     
     }


protected override void OnAppearing()
     {
         base.OnAppearing();
         RetrivePetInfo();                                 
     }

private async void RetrivePetInfo()
     {           
         var pet = await firebaseHelper.GetPet(PetName);
         if (pet != null)
         {
                

             if(pet.imageUrl!=null)
             {
                 LoadImages(pet.imageUrl);                   
             }                                            
         }
     }
1 Answers

Update your security rules with match /{allPaths=**} to indicate that public read and write access is allowed on all paths:

service firebase.storage {
  match /b/zain*******.appspot.com/o {
    match /{allPaths=**} {
      // Allow access by all users
      allow read, write;
    }
  }
}
Related