首页 > 其他分享 >Blazor文件上传异常:Did not receive any data in the allotted time

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

时间:2023-02-08 14:12:14浏览次数:41  
标签:Did await time allotted Blazor data any

最近使用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;
});

标签:Did,await,time,allotted,Blazor,data,any
From: https://www.cnblogs.com/HUGO_CM/p/17101549.html

相关文章