Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 829
Apple Geek Avatar asked Feb 23 '18 17:02

Apple Geek


1 Answers

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...

like image 89
SushiHangover Avatar answered Oct 08 '22 17:10

SushiHangover