Apple Geek
Apple Geek

Reputation: 1121

Download Image from azure blob storage and download it

I am working with Xamarin forms and I've stored an image in Azure blob storage which I'd like to download on page load and put into an image view, as of now I have this code:

using(var fileStream = imageStore.GetStream())
{
     blockBlob.DownloadToStreamAsync(fileStream);
}

This code should download the image into a file stream (Please let me know if I'm wrong) but then I need to get the image out of that file stream and set it as the image view source, but I don't know how to do that.

Upvotes: 6

Views: 1472

Answers (1)

SushiHangover
SushiHangover

Reputation: 74209

You can directly convert the stream to an Image.Source via the static method ImageSource.FromStream:

using (var fileStream = new MemoryStream())
{
    await blockBlob.DownloadToStreamAsync(fileStream);
    image.Source = ImageSource.FromStream(() => fileStream);
}

Note: DownloadToStreamAsync returns a Task, so await it...

Upvotes: 4

Related Questions