blob: dbe6bff433856eee9b23c3db1ca255d046fa3f64 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
using Microsoft.AspNetCore.Mvc;
namespace WhatApi.Endpoints;
public class DownloadContentEndpoint : BaseEndpoint
{
[HttpGet("~/{id:guid}")]
public async Task<ActionResult> HandleAsync(Guid id, CancellationToken ct = default) {
try {
var path = Path.Combine(Directory.GetCurrentDirectory(), "files", id.ToString());
await using var file = new FileStream(path, FileMode.Open);
if (!file.CanRead) return NotFound();
return File(file, "application/octet-stream", id.ToString());
} catch (Exception e) {
if (e is not FileNotFoundException) Console.WriteLine(e);
return NotFound();
}
}
}
|