Added max file size upload option. Switched from stream upload to multipart form content file upload
This commit is contained in:
@@ -10,6 +10,7 @@ public class AppConfiguration
|
||||
public AuthenticationConfig Authentication { get; set; } = new();
|
||||
public DevelopmentConfig Development { get; set; } = new();
|
||||
public ClientConfig Client { get; set; } = new();
|
||||
public KestrelConfig Kestrel { get; set; } = new();
|
||||
|
||||
public class ClientConfig
|
||||
{
|
||||
@@ -48,4 +49,9 @@ public class AppConfiguration
|
||||
{
|
||||
public bool EnableApiDocs { get; set; } = false;
|
||||
}
|
||||
|
||||
public class KestrelConfig
|
||||
{
|
||||
public int UploadLimit { get; set; } = 100;
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,10 @@ using ICSharpCode.SharpZipLib.GZip;
|
||||
using ICSharpCode.SharpZipLib.Tar;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MoonCore.Exceptions;
|
||||
using MoonCore.Extended.PermFilter;
|
||||
using MoonCore.Helpers;
|
||||
using Moonlight.ApiServer.Configuration;
|
||||
using Moonlight.Shared.Http.Requests.Admin.Sys.Files;
|
||||
using Moonlight.Shared.Http.Responses.Admin.Sys;
|
||||
|
||||
@@ -65,7 +67,11 @@ public class FilesController : Controller
|
||||
[HttpPost("create")]
|
||||
public async Task Create([FromQuery] string path)
|
||||
{
|
||||
var stream = Request.Body;
|
||||
if (Request.Form.Files.Count != 1)
|
||||
throw new HttpApiException("You need to provide exactly one file", 400);
|
||||
|
||||
var file = Request.Form.Files[0];
|
||||
var stream = file.OpenReadStream();
|
||||
|
||||
var safePath = SanitizePath(path);
|
||||
var physicalPath = PathBuilder.File(BaseDirectory, safePath);
|
||||
|
||||
@@ -71,6 +71,7 @@ public class Startup
|
||||
|
||||
await CreateWebApplicationBuilder();
|
||||
|
||||
await ConfigureKestrel();
|
||||
await RegisterAppConfiguration();
|
||||
await RegisterLogging();
|
||||
await RegisterBase();
|
||||
@@ -183,6 +184,20 @@ public class Startup
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task ConfigureKestrel()
|
||||
{
|
||||
WebApplicationBuilder.WebHost.ConfigureKestrel(kestrelOptions =>
|
||||
{
|
||||
var maxUploadInBytes = ByteConverter
|
||||
.FromMegaBytes(Configuration.Kestrel.UploadLimit)
|
||||
.Bytes;
|
||||
|
||||
kestrelOptions.Limits.MaxRequestBodySize = maxUploadInBytes;
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Plugin Loading
|
||||
|
||||
Reference in New Issue
Block a user