I have a .net 6 app that reads files from different zip files on startup and converts them to a list of Resources:
public class Resource
{
public string? Id { get; set; }
public string? MimeType { get; set; }
public byte[] Data { get; set; } = Array.Empty<byte>();
}
Currently, I just keep them in a dictionary in memory and serve them from a controller:
[HttpGet("{id}")]
public IActionResult GetResource(string id)
{
var resource = _resourceRepository.Get(id);
return File(resource.Data, resource.MimeType!);
}
I would like to incorporate the static file management in the net framework, but preferably retain the controller so that the clients can get resources using a GET resource/id.
I tried to use app.UseStaticFiles, set the RequestPath to "resource" and store the files without extension and set ServeUnknownFileTypes = true which works, I would prefer to keep the extensions to be able to browse the folders manually and keep the content-type header.
Is there any way to manage this through the controller?