无法使用媒体插件将文件上传到azure blob存储

时间:2018-02-03 14:50:33

标签: azure xamarin xamarin.forms

您好我正在使用xamarin,我正在尝试使用媒体插件和azure blob存储将照片从手机上传到azure。这是我的代码:

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);
            }

        }

然而我收到错误:错误CS1503:参数1:无法从'Plugin.Media.Abstractions.MediaFile'转换为'System.IO.Stream'(CS1503))

2 个答案:

答案 0 :(得分:1)

这是我用来获取图像流的代码

var photo = await CrossMedia.Current.TakePhotoAsync(options);
            if (photo != null)
            {
                return ImageSource.FromStream(() =>
                {
                    return photo.GetStream();
                });
            }

答案 1 :(得分:1)

这应该做的工作:

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);
    }

}