I've been searching for a while and while it should be simple, I just can't get it to work. Based on examples I've seen, this is where I got so far:
SomeAppService.cs
public async Task<FileStream> Download(long? id)
{
    var attachment = await _repository.FirstOrDefaultAsync(x => x.Id == id);
    var fileStream = new FileStream($"{attachment.FileName}.{attachment.FileExtension}", 
        FileMode.Create, FileAccess.Write);
    fileStream.Write(attachment.File, 0, attachment.File.Length);
    return fileStream;
}
As it can be noticed, "FileName", "FileExtension" and "File" (which is the forementioned byte array) are stored in a database. The attachment can be any kind of file, save for banned extensions in the Upload method (not shown). Then in my controller I have:
SomeController.cs
[AllowAnonymous]
[HttpGet("Download/{id}")]
public async Task<IActionResult> Download(long? id)
{
    var fileStream = await appService.Download(id);
    return new FileStreamResult(fileStream, "application/octet-stream");
}
However, when I hit the download endpoint, I end up with a file named "response", no extension, with 0 bytes.
Resources:
Return file in ASP.Net Core Web API
Return a FileResult from a byte[]
Save and load MemoryStream to/from a file (Response with 255 upvotes gave me de idea of how to turn a byte array into a filestream, but I don't know if that works)
attachment.Filein aMemoryStreamand pass that to theFileStreamResultconstructor directly. There's also a FileContentResult you could passattachment.Fileto instead of creating a stream.FileStreamreturned byDownload()will be positioned immediately after the data you've just written. DoesSeek()ing back to the beginning of theStreambeforereturning it produce a different result?return File(byteArray, "contentType");content type is for exampleapplication/pdf