Reputation: 1121
Hi i'm using xamarin and I'm trying to upload a photo from my phone to azure using the media plugin and azure blob storage. Here's my code:
async void selectImage(object sender, System.EventArgs e)
{
var image = await CrossMedia.Current.PickPhotoAsync();
//System.IO.Stream stream = t;
CloudBlockBlob blockBlob = sermonsContainer.GetBlockBlobReference("myblob");
using (var fileStream = image)
{
blockBlob.UploadFromStreamAsync(fileStream);
}
}
however i'm getting the error: Error CS1503: Argument 1: cannot convert from 'Plugin.Media.Abstractions.MediaFile' to 'System.IO.Stream' (CS1503) )
Upvotes: 1
Views: 142
Reputation: 2708
This should do the job:
async void selectImage(object sender, System.EventArgs e)
{
var image = await CrossMedia.Current.PickPhotoAsync();
//System.IO.Stream stream = t;
CloudBlockBlob blockBlob = sermonsContainer.GetBlockBlobReference("myblob");
using (var fileStream = image.GetStream ())
{
blockBlob.UploadFromStreamAsync(fileStream);
}
}
Upvotes: 1
Reputation: 276
This is code which I use to get stream of image
var photo = await CrossMedia.Current.TakePhotoAsync(options);
if (photo != null)
{
return ImageSource.FromStream(() =>
{
return photo.GetStream();
});
}
Upvotes: 1