feat: 增加文件上传进度消息
This commit is contained in:
parent
8b2c594880
commit
6df1dbd6ae
4 changed files with 17 additions and 11 deletions
|
@ -69,14 +69,14 @@ public class WebSocPipeLine<TSocket>(TSocket socket, bool isAES) : AbsPipeLine(i
|
|||
using var content = new MultipartFormDataContent();
|
||||
using var fileStream = new FileStream(filePath, FileMode.Open);
|
||||
// TODO 上传进度回调
|
||||
// var progress = new Progress<double>(
|
||||
// (current) =>
|
||||
// {
|
||||
// progressCb(current);
|
||||
// }
|
||||
// );
|
||||
//var fileContent = new ProgressStreamContent(fileStream, progress);
|
||||
content.Add(new StreamContent(fileStream), "file", Path.GetFileName(filePath));
|
||||
var progress = new Progress<double>(
|
||||
(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)
|
||||
{
|
||||
|
|
|
@ -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<double> 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<double> Progress = progress;
|
||||
|
||||
protected override async Task SerializeToStreamAsync(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -53,6 +53,7 @@ public class SyncFilesController(RemoteSyncServerFactory factory, SqliteDbContex
|
|||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
[DisableRequestSizeLimit]
|
||||
[HttpPost("/UploadFile")]
|
||||
public async Task<IActionResult> UploadFile(IFormFile file)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue