Blazor文件上传异常:Did not receive any data in the allotted time

最近使用Blazor做文件上传,无论是Page还是Service处理,使用以下代码,都会报异常错误Did not receive any data in the allotted time

//Page页面 微软官网文档:https://learn.microsoft.com/zh-cn/aspnet/core/blazor/file-uploads?view=aspnetcore-5.0&pivots=server
await using FileStream fs = new(path, FileMode.Create);
await browserFile.OpenReadStream().CopyToAsync(fs);

//服务端 通过IFormFile
await using var memoryStream = new MemoryStream();
await input.File.OpenReadStream().CopyToAsync(memoryStream);

原因:估计是使用.Net7。

解决方案:

常规项目在Program.cs,添加代码:

builder.Services
    .AddServerSideBlazor()
    .AddHubOptions(opt =>
    {
        opt.DisableImplicitFromServicesParameters = true;
    });

使用Abp的项目在XXXModule.cs中,添加代码:

Configure<HubOptions>(options =>
{
    options.DisableImplicitFromServicesParameters = true;
});
posted @ 2023-02-08 14:05  HUGO.CM  阅读(168)  评论(1编辑  收藏  举报