【发布时间】:2020-10-16 03:28:55
【问题描述】:
我有一个文件,用户将使用BlazorInputFile 在浏览器中选择该文件,如Steve Sanderson 所述。
选择后,我想使用 System.Security.Cryptography.MD5 计算文件的校验和,类似于 Calculate MD5 checksum for a file 的答案中描述的内容。
但是,当我尝试这个时遇到System.NotSupportedException:
private string GetMd5ForFile(IFileListEntry file)
{
using (var md5 = MD5.Create())
{
return Convert.ToBase64String(md5.ComputeHash(this.file.Data));
}
}
一些异常细节是:
> Message: "Synchronous reads are not supported"
> Source : "BlazorInputFile"
> Stack : "at BlazorInputFile.FileListEntryStream.Read(Byte[] buffer, Int32 offset, Int32 count)"
我知道ComputeHash() 接受byte 的数组。到目前为止,我尝试将 BlazorInputFile 的流转换为熟悉的类型,或者使用自己的方法将字节读取到数组中 FileStream,但没有成功。
【问题讨论】:
标签: c# .net md5 blazor blazorinputfile