MeowStash/Controllers/ResourceController.cs

38 lines
1 KiB
C#
Raw Permalink Normal View History

2023-03-22 11:32:04 +01:00
using MeowStash.Services;
2023-01-08 14:54:50 +01:00
using Microsoft.AspNetCore.Mvc;
namespace MeowStash.Controllers;
[Route("/api/resource")]
[ApiController]
public class ResourceController : ControllerBase
{
2023-03-22 11:32:04 +01:00
public ResourceController(FileIOService io)
{
_io = io;
}
private readonly FileIOService _io;
[HttpPost("upload")]
public async Task<IActionResult> UploadFiles([FromForm] IFormFileCollection files)
2023-01-08 14:54:50 +01:00
{
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();
}
2023-03-22 11:32:04 +01:00
[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();
}
2023-01-08 14:54:50 +01:00
}