feat: added feature of http/2 chunk load
This commit is contained in:
33
UploadController.cs
Normal file
33
UploadController.cs
Normal 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
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user