0

I am trying to enable the functionality of video upload up to 190MB. I am using .Net core with Ocelot Gateway. I am able to successfully upload videos up to 190MB locally. But when I try to upload with Ocelot Gateway(on test environment), I am getting a 404 error. We have Cloudflare on the test environment and that is enabled for up to 200MB video upload.

I have applied following changes: In web.config of web project and gateway project

<system.web>
    <httpRuntime maxRequestLength="220200960" />
</system.web>

<requestLimits maxAllowedContentLength="220200960" />

On API Endpoint:

[RequestSizeLimit(220200960)]
[RequestFormLimits(MultipartBodyLengthLimit = 220200960)]

In web startup.cs

services.Configure<IISServerOptions>(options =>
{
  options.MaxRequestBodySize = int.MaxValue;
});
services.Configure<KestrelServerOptions>(options =>
{
  options.Limits.MaxRequestBodySize = int.MaxValue; 
});
services.Configure<FormOptions>(x =>
{
  x.ValueLengthLimit = int.MaxValue;
  x.MultipartBodyLengthLimit = int.MaxValue; 
  x.MultipartHeadersLengthLimit = int.MaxValue;
});

I am getting the following warning in Gateway:

Ocelot.Responder.Middleware.ResponderMiddleware[0] requestId: 0HMFB1RBKJ31C:00000001, previousRequestId: no previous request id, message: Error Code: UnmappableRequestError Message: Error when parsing incoming request, exception: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.IO.MemoryStream.set_Capacity(Int32 value) at System.IO.MemoryStream.EnsureCapacity(Int32 value) at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.IO.MemoryStream.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.CopyToAsyncInternal(Stream destination, CancellationToken cancellationToken) at Ocelot.Request.Mapper.RequestMapper.ToByteArray(Stream stream) at Ocelot.Request.Mapper.RequestMapper.MapContent(HttpRequest request) at Ocelot.Request.Mapper.RequestMapper.Map(HttpRequest request, DownstreamRoute downstreamRoute) errors found in ResponderMiddleware. Setting error response for request path:/v1/File/CreateFile, request method: POST

Nothing above helped me. Any help would be appreciated. Thank you in advance.

Dhwani
  • 7,484
  • 17
  • 78
  • 139

1 Answers1

0

Looking at your stack trace, it mentions as out of memory exception, which could point towards an issue copying such a large file into memory (if your server has low free memory). Have you verified your server has > 200 MB of free memory at the time of upload?

I also found this post, which sounds like a somewhat similar issue with Ocelot - https://github.com/ThreeMammals/Ocelot/issues/884

Could try setting MaxRequestBodySize to null to see what happens? Although they were not receiving 'out of memory' exception, so could be unrelated.

David
  • 1,007
  • 7
  • 14