16 Answer(s)
-
0
private async Task<AppFileDescriptorDto> UploadFileAsync(IBrowserFile file) { using (var ms = new MemoryStream()) { await file.OpenReadStream(long.MaxValue).CopyToAsync(ms); ms.Seek(0, SeekOrigin.Begin); return await ContractAttachmentsAppService.UploadFileAsync(new RemoteStreamContent(ms, file.Name, file.ContentType)); } } 600MB左右的文件会报 内存溢出Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
好的, 我反馈给suite团队, 你可以使用文件流试试
private async Task<AppFileDescriptorDto> UploadFileAsync(IBrowserFile file) { // 直接使用文件流,不加载到 MemoryStream using var stream = file.OpenReadStream(long.MaxValue); return await ContractAttachmentsAppService.UploadFileAsync( new RemoteStreamContent(stream, file.Name, file.ContentType)); }Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
info: System.Net.Http.HttpClient.Contract.LogicalHandler[100] Start processing HTTP request POST https://localhost:44333/api/contract/contract-attachments/upload-file?* invoke-js.ts:242 info: System.Net.Http.HttpClient.Contract.ClientHandler[100] Sending HTTP request POST https://localhost:44333/api/contract/contract-attachments/upload-file?* HTGL:1 The resource https://localhost:44333/_content/Excubo.Blazor.TreeViews/Excubo.Blazor.TreeViews.ggbo2a6x37.bundle.scp.css was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate
asvalue and it is preloaded intentionally. HTGL:1 The resource [Violation] Forced reflow while executing JavaScript took 116msblazor.web.js:1 Cannot enlarge memory, requested 2586399504 bytes, but the limit is 2147483648 bytes! 报错了.
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
是的, 你可以这样试试
private async Task<AppFileDescriptorDto> UploadFileAsync(IBrowserFile file) { // using (var ms = file.OpenReadStream(2L*1024*1024*1024)) // { // return await UpFilesAppService.UploadFileAsync(new RemoteStreamContent(ms, file.Name, file.ContentType)); // } await using (var stream = file.OpenReadStream(MaxUpFileFsFileUploadSize)) { using (var content = new MultipartFormDataContent()) { using (var fileContent = new StreamContent(stream)) { fileContent.Headers.ContentType = new MediaTypeHeaderValue(file.ContentType ?? "application/octet-stream"); content.Add(fileContent, "input", file.Name); using var request = new HttpRequestMessage(HttpMethod.Post, "https://localhost:44362/api/app/up-files/upload-file"); var token = await AccessTokenProvider.GetTokenAsync(); if (!token.IsNullOrWhiteSpace()) { request.SetBearerToken(token); } request.Content = content; request.SetBrowserRequestStreamingEnabled(true); using var response = await new HttpClient().SendAsync(request, HttpCompletionOption.ResponseHeadersRead); response.EnsureSuccessStatusCode(); var dto = await response.Content.ReadFromJsonAsync<AppFileDescriptorDto>(); return dto!; } } } }Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
You also need to configure the backend limit.
Log.Information("Starting Uploadtest.HttpApi.Host."); var builder = WebApplication.CreateBuilder(args); builder.WebHost.ConfigureKestrel(o => { o.Limits.MaxRequestBodySize = 2L*1024 * 1024 * 1024; }); builder.Services.Configure<FormOptions>(o => { o.MultipartBodyLengthLimit = 2L*1024 * 1024 * 1024; });Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
你还可以继续使用应用服务而不是手动创建HttpClient
public override void PreConfigureServices(ServiceConfigurationContext context) { PreConfigure<AbpHttpClientBuilderOptions>(options => { options.ProxyClientBuildActions.Add((_, builder) => { builder.AddHttpMessageHandler<BrowserRequestStreamingHandler>(); }); }); }public sealed class BrowserRequestStreamingHandler : DelegatingHandler, ITransientDependency { protected override async Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { request.SetBrowserRequestStreamingEnabled(true); return await base.SendAsync(request, cancellationToken); } }Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
