diff --git a/Server/Common/ConnectPipeline.cs b/Server/Common/ConnectPipeline.cs index 9b41b35..22cbc12 100644 --- a/Server/Common/ConnectPipeline.cs +++ b/Server/Common/ConnectPipeline.cs @@ -69,14 +69,14 @@ public class WebSocPipeLine(TSocket socket, bool isAES) : AbsPipeLine(i using var content = new MultipartFormDataContent(); using var fileStream = new FileStream(filePath, FileMode.Open); // TODO 上传进度回调 - // var progress = new Progress( - // (current) => - // { - // progressCb(current); - // } - // ); - //var fileContent = new ProgressStreamContent(fileStream, progress); - content.Add(new StreamContent(fileStream), "file", Path.GetFileName(filePath)); + var progress = new Progress( + (current) => + { + progressCb(current); + } + ); + var fileContent = new ProgressStreamContent(fileStream, progress); + content.Add(fileContent, "file", Path.GetFileName(filePath)); var it = await client.PostAsync("http://" + url + "/UploadFile", content); if (it.StatusCode != System.Net.HttpStatusCode.OK) { diff --git a/Server/Common/ProgressStreamContent.cs b/Server/Common/ProgressStreamContent.cs index 5d22d13..4130261 100644 --- a/Server/Common/ProgressStreamContent.cs +++ b/Server/Common/ProgressStreamContent.cs @@ -1,12 +1,17 @@ +using System; using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading; namespace Common; public class ProgressStreamContent(Stream stream_, IProgress progress) - : StreamContent(stream_, 4096) + : StreamContent(stream_, 1024 * 1024) { private readonly Stream FileStream = stream_; - private readonly int BufferSize = 4096; + private readonly int BufferSize = 1024 * 1024; private readonly IProgress Progress = progress; protected override async Task SerializeToStreamAsync( diff --git a/Server/FileSqlServerSync.sln b/Server/FileSqlServerSync.sln index 4d57f6b..b2cabc5 100644 --- a/Server/FileSqlServerSync.sln +++ b/Server/FileSqlServerSync.sln @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalServer", "LocalServer\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerTest", "ServerTest\ServerTest.csproj", "{0D507943-43A3-4227-903F-E123A5CAF7F4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{3EED9D63-BC7B-455F-BA15-95BB52311ED8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common\Common.csproj", "{3EED9D63-BC7B-455F-BA15-95BB52311ED8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Server/RemoteServer/Controllers/RemoteServerController.cs b/Server/RemoteServer/Controllers/RemoteServerController.cs index d59bcd6..4a3842d 100644 --- a/Server/RemoteServer/Controllers/RemoteServerController.cs +++ b/Server/RemoteServer/Controllers/RemoteServerController.cs @@ -53,6 +53,7 @@ public class SyncFilesController(RemoteSyncServerFactory factory, SqliteDbContex /// /// /// + [DisableRequestSizeLimit] [HttpPost("/UploadFile")] public async Task UploadFile(IFormFile file) {