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 content = new MultipartFormDataContent();
|
||||||
using var fileStream = new FileStream(filePath, FileMode.Open);
|
using var fileStream = new FileStream(filePath, FileMode.Open);
|
||||||
// TODO 上传进度回调
|
// TODO 上传进度回调
|
||||||
// var progress = new Progress<double>(
|
var progress = new Progress<double>(
|
||||||
// (current) =>
|
(current) =>
|
||||||
// {
|
{
|
||||||
// progressCb(current);
|
progressCb(current);
|
||||||
// }
|
}
|
||||||
// );
|
);
|
||||||
//var fileContent = new ProgressStreamContent(fileStream, progress);
|
var fileContent = new ProgressStreamContent(fileStream, progress);
|
||||||
content.Add(new StreamContent(fileStream), "file", Path.GetFileName(filePath));
|
content.Add(fileContent, "file", Path.GetFileName(filePath));
|
||||||
var it = await client.PostAsync("http://" + url + "/UploadFile", content);
|
var it = await client.PostAsync("http://" + url + "/UploadFile", content);
|
||||||
if (it.StatusCode != System.Net.HttpStatusCode.OK)
|
if (it.StatusCode != System.Net.HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Common;
|
namespace Common;
|
||||||
|
|
||||||
public class ProgressStreamContent(Stream stream_, IProgress<double> progress)
|
public class ProgressStreamContent(Stream stream_, IProgress<double> progress)
|
||||||
: StreamContent(stream_, 4096)
|
: StreamContent(stream_, 1024 * 1024)
|
||||||
{
|
{
|
||||||
private readonly Stream FileStream = stream_;
|
private readonly Stream FileStream = stream_;
|
||||||
private readonly int BufferSize = 4096;
|
private readonly int BufferSize = 1024 * 1024;
|
||||||
private readonly IProgress<double> Progress = progress;
|
private readonly IProgress<double> Progress = progress;
|
||||||
|
|
||||||
protected override async Task SerializeToStreamAsync(
|
protected override async Task SerializeToStreamAsync(
|
||||||
|
|
|
@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalServer", "LocalServer\
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerTest", "ServerTest\ServerTest.csproj", "{0D507943-43A3-4227-903F-E123A5CAF7F4}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerTest", "ServerTest\ServerTest.csproj", "{0D507943-43A3-4227-903F-E123A5CAF7F4}"
|
||||||
EndProject
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|
|
@ -53,6 +53,7 @@ public class SyncFilesController(RemoteSyncServerFactory factory, SqliteDbContex
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
[DisableRequestSizeLimit]
|
||||||
[HttpPost("/UploadFile")]
|
[HttpPost("/UploadFile")]
|
||||||
public async Task<IActionResult> UploadFile(IFormFile file)
|
public async Task<IActionResult> UploadFile(IFormFile file)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue