Program.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Amazon;
  2. using Amazon.S3;
  3. using Amazon.S3.Model;
  4. using Microsoft.AspNetCore.Http.Features;
  5. var builder = WebApplication.CreateBuilder(args);
  6. // Add services to the container.
  7. builder.Services.AddControllers();
  8. builder.Services.AddControllersWithViews();
  9. builder.Services.Configure<FormOptions>(options =>
  10. {
  11. options.MultipartBodyLengthLimit = 268435456;
  12. });
  13. //.NET CORE Aws S3 ʹÓÃ
  14. //https://blog.csdn.net/qq_36694046/article/details/136672057
  15. // ¹Ù·½Îĵµ https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/userguide/optimizing-performance.html
  16. var s3Endpoint ="http://192.168.8.160:8080";
  17. var s3AccessKey = "YR3H8OQKRC5PP6JZLYCQ";
  18. var s3SecretKey = "BQFGIB3vzGtdjXETSp5oD0dq28r0wbUwbx9XG2y8";
  19. var s3Configuration = new AmazonS3Config
  20. {
  21. RegionEndpoint = RegionEndpoint.USEast1,
  22. ServiceURL = s3Endpoint,
  23. ForcePathStyle = true
  24. };
  25. var s3Client=new AmazonS3Client(s3AccessKey, s3SecretKey, s3Configuration);
  26. builder.Services.AddSingleton<IAmazonS3>(sp => s3Client);
  27. var app = builder.Build();
  28. // Configure the HTTP request pipeline.
  29. app.UseHttpsRedirection();
  30. app.UseAuthorization();
  31. app.MapControllers();
  32. app.Run();