C
C#2y ago
V0FBU1VM

❔ RequestSizeLimit on Actions not Working!

I have an action that is uploading a large file. The file size is 189mb. For some reason I'm getting this error 413 Error: Request Entity Too Large. I even tried adding the RequestSizeLimit attribute on top of the action but it still has no effect. Here is the action
[RequestSizeLimit(int.MaxValue)]
[HttpPost]
[Authorize]
[SwaggerOperation("An action for creating an episode.")]
public async Task<IActionResult> CreateEpisodeAsync([FromForm] CreateEpisodeRequest request,
CancellationToken cancellationToken = default)
{
var result = await _mutationService.CreateEpisodeAsync(request, cancellationToken);
var response = result.ToApiResponse();

if (result.IsSuccessful)
response.StatusCode = HttpStatusCode.Created;
else
response.StatusCode = result.ErrorCode switch
{
ErrorCode.NotFound => HttpStatusCode.NotFound,
ErrorCode.InternalServerError => HttpStatusCode.InternalServerError,
_ => HttpStatusCode.BadRequest
};

return response.ToActionResult();
}
[RequestSizeLimit(int.MaxValue)]
[HttpPost]
[Authorize]
[SwaggerOperation("An action for creating an episode.")]
public async Task<IActionResult> CreateEpisodeAsync([FromForm] CreateEpisodeRequest request,
CancellationToken cancellationToken = default)
{
var result = await _mutationService.CreateEpisodeAsync(request, cancellationToken);
var response = result.ToApiResponse();

if (result.IsSuccessful)
response.StatusCode = HttpStatusCode.Created;
else
response.StatusCode = result.ErrorCode switch
{
ErrorCode.NotFound => HttpStatusCode.NotFound,
ErrorCode.InternalServerError => HttpStatusCode.InternalServerError,
_ => HttpStatusCode.BadRequest
};

return response.ToActionResult();
}
4 Replies
n8ta
n8ta2y ago
Stack Overflow
Increase upload file size in Asp.Net core
Currently, I am working with Asp.Net Core and MVC6 need to upload file size unlimited. I have searched its solution but still not getting the actual answer. I have tried this link If anyone have ...
V0FBU1VM
V0FBU1VMOP2y ago
@Nathaniel TA Thanks mate, after a lot of testing. I realized it was using IIS in Debug and Kestrel in Production. I changed it to use Kestrel on both debug and production. For some reason, the attribute then started working. It sounds weird.
n8ta
n8ta2y ago
@SwaggerLife I think IIS has an internal limit that was rejecting it before it even reached your service. np
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server