I have this code that uploads a file. My problem is that AuthorizationCheck fires only after the file is uploaded. If the file is larger than 20MB the AuthorizationCheck will not fire at all and the request will return 404. Is it possible to validate the request headers before the file steam is sent? If the request is not authorized then the file should be blocked from uploading to the server. Also it is not clear why when I upload a large file it is being uploaded fully and only then 404 is being returned...
[RequestSizeLimit(21_000_000)]
[Authorize(Policy = "AuthorizationCheck")]
public async Task<IActionResult> Upload(IFormFile file)
{
using (var stream = file.OpenReadStream())
{
await StoreFileAsync(stream);
}
}