Browse Source

set max limit to 2GB

HOME 1 month ago
parent
commit
0851e033f1
1 changed files with 20 additions and 7 deletions
  1. 20 7
      ImageConvertService/Program.cs

+ 20 - 7
ImageConvertService/Program.cs

@@ -1,5 +1,11 @@
+using System.Text.Json.Serialization;
 using ImageConvertService.Biz;
 using ImageConvertService.ExceptionHandling;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Localization;
+using Microsoft.AspNetCore.Server.Kestrel.Core;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
 
 var builder = WebApplication.CreateBuilder(args);
 
@@ -7,27 +13,34 @@ var builder = WebApplication.CreateBuilder(args);
 // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
 builder.Services.AddEndpointsApiExplorer();
 builder.Services.AddSwaggerGen();
-builder.Services.AddControllers((options =>
-{
-    options.Filters.Add<UserFriendlyExceptionFilter>();
-}));
+
+builder.Services
+    .AddControllers(options => options.Filters.Add<UserFriendlyExceptionFilter>())
+    .AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
 
 builder.Services.AddSingleton<ImageConverter>();
 builder.Services.AddSingleton<ArchiveFileAccessor>();
+builder.Services.AddSingleton<PdfImageReader>();
+
+
+builder.Services.Configure<KestrelServerOptions>(options =>
+{
+    options.Limits.MaxRequestBodySize = 2000 * 1024 * 1024; // 设置最大请求体大小 2GB
+});
 
 var app = builder.Build();
 
 // Configure the HTTP request pipeline.
 //if (app.Environment.IsDevelopment())
 //{
-    app.UseSwagger();
-    app.UseSwaggerUI();
+app.UseSwagger();
+app.UseSwaggerUI();
 //}
 
 //app.UseHttpsRedirection();
 
 //app.AddExample();
-app.MapControllers();
+app.MapControllers().WithFormOptions(multipartBodyLengthLimit: 2_000_000_000L); // 设置表单最大请求体大小 2GB
 
 app.Run();