diff --git a/Moonlight.ApiServer/Configuration/AppConfiguration.cs b/Moonlight.ApiServer/Configuration/AppConfiguration.cs
index 9a63565e..307114a5 100644
--- a/Moonlight.ApiServer/Configuration/AppConfiguration.cs
+++ b/Moonlight.ApiServer/Configuration/AppConfiguration.cs
@@ -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;
+ }
}
\ No newline at end of file
diff --git a/Moonlight.ApiServer/Http/Controllers/Admin/Sys/FilesController.cs b/Moonlight.ApiServer/Http/Controllers/Admin/Sys/FilesController.cs
index 2a1fedde..5bd609a1 100644
--- a/Moonlight.ApiServer/Http/Controllers/Admin/Sys/FilesController.cs
+++ b/Moonlight.ApiServer/Http/Controllers/Admin/Sys/FilesController.cs
@@ -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);
diff --git a/Moonlight.ApiServer/Startup.cs b/Moonlight.ApiServer/Startup.cs
index 19d3bc25..10235a7b 100644
--- a/Moonlight.ApiServer/Startup.cs
+++ b/Moonlight.ApiServer/Startup.cs
@@ -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
diff --git a/Moonlight.Client/Implementations/SysFileSystemProvider.cs b/Moonlight.Client/Implementations/SysFileSystemProvider.cs
index e12ed16e..b4c98c9a 100644
--- a/Moonlight.Client/Implementations/SysFileSystemProvider.cs
+++ b/Moonlight.Client/Implementations/SysFileSystemProvider.cs
@@ -47,7 +47,13 @@ public class SysFileSystemProvider : IFileSystemProvider, ICompressFileSystemPro
}
public async Task Create(string path, Stream stream)
- => await HttpApiClient.PostStream($"{BaseApiUrl}/create?path={path}", stream);
+ {
+ var content = new MultipartFormDataContent();
+
+ content.Add(new StreamContent(stream), "file", "x");
+
+ await HttpApiClient.Post($"{BaseApiUrl}/create?path={path}", content);
+ }
public async Task Move(string oldPath, string newPath)
=> await HttpApiClient.Post($"{BaseApiUrl}/move?oldPath={oldPath}&newPath={newPath}");
diff --git a/Moonlight.Client/Moonlight.Client.csproj b/Moonlight.Client/Moonlight.Client.csproj
index 6f5101d7..b996de40 100644
--- a/Moonlight.Client/Moonlight.Client.csproj
+++ b/Moonlight.Client/Moonlight.Client.csproj
@@ -27,7 +27,7 @@
-
+