0
votes

im using firebase storage to store a profile image of the users

the upload working good,

when i want to view the image as an imagesource i use this code:

public async Task<string> LoadImages()
        {
            var stroageImage = await new FirebaseStorage("foodymood-ba7aa.appspot.com")
                .Child("Users/" + Settings.LastUserID)
                .Child("ProfileImage.jpg")
                .GetDownloadUrlAsync();
            string imgurl = stroageImage;
            return imgurl;
        }

it returns the download url:

"https://firebasestorage.googleapis.com/v0/b/foodymood-ba7aa.appspot.com/o/Users%2F0BCAruzb4xP1chAeaLhmnwfTue53%2FProfileImage.jpg?alt=media&token=b69e1de0-1bac-4ceb-ad7d-0c3b1d313a2c"

now i dont know how to use this url for viewing the image..

1

1 Answers

0
votes

fixed with this code:

 public async Task<ImageSource> LoadImages()
        {
            var webClient = new WebClient();
            var stroageImage = await new FirebaseStorage("foodymood-ba7aa.appspot.com")
                .Child("Users/" + Settings.LastUserID)
                .Child("ProfileImage.jpg")
                .GetDownloadUrlAsync();
            string imgurl = stroageImage;
            byte[] imgBytes = webClient.DownloadData(imgurl);
            //string img = Convert.ToBase64String(imgBytes);
            var img = ImageSource.FromStream(() => new MemoryStream(imgBytes));
            return img;
        }