选择了图像文件后,我设法进行了预览(使用Blazorise的FileEdit组件)。我的代码如下:
...other code
<FileEdit Changed="@OnChanged" Filter="image/*,video/mp4" />
<img src="@_imageData" style="width: 90%" />
@code{
string _imageData = String.Empty;
async Task OnChanged(FileChangedEventArgs e)
{
try
{
foreach (var file in e.Files)
{
// A stream is going to be the destination stream we're writing to.
using (var stream = new MemoryStream())
{
// Here we're telling the FileEdit where to write the upload result
await file.WriteToStreamAsync(stream);
_imageData = $"data:image/jpg;base64,{Convert.ToBase64String(stream.ToArray())}";
}
}
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
}
finally
{
StateHasChanged();
}
}
}
...other code
我认为“ _imageData = ...”部分中正在处理允许使用该文件的内存。
问题是,对于视频文件,我该如何实现?