feat: added feature of http/2 chunk load

This commit is contained in:
2025-07-08 14:41:46 +03:00
parent a2555a7ce5
commit 4665c11e25
8 changed files with 143 additions and 2 deletions

33
UploadController.cs Normal file
View File

@@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
namespace HTTP2FileStreams;
[ApiController]
[Route("api/[controller]")]
public class UploadController : ControllerBase
{
[HttpPost]
[DisableFormValueModelBinding] // Отключаем стандартный парсинг формы
public async Task<IActionResult> Upload()
{
// Получаем имя файла из заголовка
var fileName = Request.Headers["X-File-Name"].ToString();
if (string.IsNullOrEmpty(fileName))
return BadRequest("File name header is missing");
fileName = Uri.UnescapeDataString(fileName);
// Потоковая запись файла
if (!Directory.Exists("Uploads"))
Directory.CreateDirectory("Uploads");
var filePath = Path.Combine("Uploads", fileName);
await using var fileStream = System.IO.File.Create(filePath);
await Request.Body.CopyToAsync(fileStream);
return Ok(new {
fileName,
size = fileStream.Length
});
}
}