MeowStash/Controllers/ResourceController.cs
2024-05-06 13:12:26 +02:00

37 lines
1 KiB
C#

using MeowStash.Services;
using Microsoft.AspNetCore.Mvc;
namespace MeowStash.Controllers;
[Route("/api/resource")]
[ApiController]
public class ResourceController : ControllerBase
{
public ResourceController(FileIOService io)
{
_io = io;
}
private readonly FileIOService _io;
[HttpPost("upload")]
public async Task<IActionResult> UploadFiles([FromForm] IFormFileCollection files)
{
foreach (var file in files)
{
await using var fos = System.IO.File.OpenWrite($"/tmp/{file.FileName}");
await file.OpenReadStream().CopyToAsync(fos);
Console.WriteLine($"File: /tmp/{file.FileName} written...");
}
return NoContent();
}
[HttpPost("upload/fragment/{id}")]
public async Task<IActionResult> UploadFileFragment([FromRoute] int uploadId, [FromBody] byte[] dataPacket)
{
using var buffer = new MemoryStream(dataPacket);
await _io.WritePartialFile(uploadId, buffer);
return NoContent();
}
}