Open Closed

Error uploading file larger than 2 GB using microservices #4166


User avatar
0
yolier.galan@rockblast.cl created
  • ABP Framework version: v6.0.1
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Use microservice template: yes
  • Exception message and stack trace:
web-gateway_e8dbcfd8-3]: [15:23:09 INF] CORS policy execution successful.
[web-gateway_e8dbcfd8-3]: [15:23:09 INF] Request finished HTTP/1.1 OPTIONS https://localhost:44325/api/file-management/file-descriptor/upload?directoryId=3a080000-9d8c-c259-9807-98257c036810 - - - 204 - - 0.3812ms
[web-gateway_e8dbcfd8-3]: [15:23:09 INF] Request starting HTTP/1.1 POST https://localhost:44325/api/file-management/file-descriptor/upload?directoryId=3a080000-9d8c-c259-9807-98257c036810 multipart/form-data;+boundary=---------------------------239247365239037117843134239485 3045796267
[web-gateway_e8dbcfd8-3]: [15:23:09 INF] CORS policy execution successful.
[web-gateway_e8dbcfd8-3]: [15:23:09 DBG] requestId: 0HMMOCVPSLJTM:00000007, previousRequestId: no previous request id, message: ocelot pipeline started
[web-gateway_e8dbcfd8-3]: [15:23:09 DBG] requestId: 0HMMOCVPSLJTM:00000007, previousRequestId: no previous request id, message: Upstream url path is /api/file-management/file-descriptor/upload
[web-gateway_e8dbcfd8-3]: [15:23:09 DBG] requestId: 0HMMOCVPSLJTM:00000007, previousRequestId: no previous request id, message: downstream templates are /api/file-management/{everything}
[web-gateway_e8dbcfd8-3]: [15:23:17 WRN] requestId: 0HMMOCVPSLJTM:00000007, previousRequestId: no previous request id, message: Error Code: UnmappableRequestError Message: Error when parsing incoming request, exception: System.IO.IOException: Stream was too long.
[web-gateway_e8dbcfd8-3]: at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
[web-gateway_e8dbcfd8-3]: at System.IO.MemoryStream.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)
[web-gateway_e8dbcfd8-3]: --- End of stack trace from previous location ---
[web-gateway_e8dbcfd8-3]: at System.IO.Pipelines.PipeReader.<CopyToAsync>g__Awaited|15_1(ValueTask writeTask)
[web-gateway_e8dbcfd8-3]: at System.IO.Pipelines.PipeReader.CopyToAsyncCore[TStream](TStream destination, Func`4 writeAsync, CancellationToken cancellationToken)
[web-gateway_e8dbcfd8-3]: at Ocelot.Request.Mapper.RequestMapper.ToByteArray(Stream stream)
[web-gateway_e8dbcfd8-3]: at Ocelot.Request.Mapper.RequestMapper.MapContent(HttpRequest request)
[web-gateway_e8dbcfd8-3]: at Ocelot.Request.Mapper.RequestMapper.Map(HttpRequest request, DownstreamRoute downstreamRoute) errors found in ResponderMiddleware. Setting error response for request path:/api/file-management/file-descriptor/upload, request method: POST
[web-gateway_e8dbcfd8-3]: [15:23:17 DBG] requestId: 0HMMOCVPSLJTM:00000007, previousRequestId: no previous request id, message: ocelot pipeline finished
[web-gateway_e8dbcfd8-3]: [15:23:17 INF] Request finished HTTP/1.1 POST https://localhost:44325/api/file-management/file-descriptor/upload?directoryId=3a080000-9d8c-c259-9807-98257c036810 multipart/form-data;+boundary=---------------------------239247365239037117843134239485 3045796267 - 404 0 - 8055.6041ms
[web-gateway_e8dbcfd8-3]: [15:23:18 INF] Connection id "0HMMOCVPSLJTM", Request id "0HMMOCVPSLJTM:00000007": the application completed without reading the entire request body.
  • Steps to reproduce the issue:"

0.- Use the microservices template 1.- Create a microservices Main 2.- Add the FileManagement module to Main microservices 3.- Configure Kestrel in gateways/Web Module (Program.cs file) to allow uploading files larger than 28mb.

// Prevent Ocelot error when loading a file with size > 28 mb
builder.WebHost.UseKestrel(options => {
    options.Limits.MaxRequestBodySize = long.MaxValue;
});

4.- Configure Kestrel in services/Main Module (Program.cs file) to allow uploading files larger than 28mb.

// Prevent Ocelot error when loading a file with size > 28 mb
builder.WebHost.UseKestrel(options => {
    options.Limits.MaxRequestBodySize = long.MaxValue;
});

5.- Attempts to upload files larger than 2.0 GB

Question:

In case the above bug cannot be solved in the short term, how to avoid CORS from Angular when trying to access directly to the main microservice


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    This seems Ocelot problem. cannot be solved in the short term.

    https://github.com/ThreeMammals/Ocelot/issues/695

    how to avoid CORS from Angular when trying to access directly to the main microservice

    You can configure the CORS on the main microservice.

    App: CorsOrigins

  • User Avatar
    0
    yolier.galan@rockblast.cl created

    hi

    This seems Ocelot problem. cannot be solved in the short term.

    https://github.com/ThreeMammals/Ocelot/issues/695

    how to avoid CORS from Angular when trying to access directly to the main microservice

    You can configure the CORS on the main microservice.

    App: CorsOrigins

    Hi, thanks for you response,

    I have configured in the appsettings.json of the HttpApi.Host the following settings:

       "App": {
        "SelfUrl": "https://localhost:44559",
        "CorsOrigins": "https://localhost:44325,https://localhost:44353,http://localhost:4200,http://localhost:4200/"
      },
    

    I have the follow error in the Angular UI (the main service is running in the port 44559 )

    Cross-origin request blocked: The same origin policy does not allow reading of remote resources at https://localhost:44559/api/main-service/assets?skipCount=0&maxResultCount=10. (Reason: CORS request not successful). Status code: (null).
    

    Is the configuration correct or missing something?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    HI

    Have you tried the privacy mode of the browser? Sometimes the browser will cache CORS settings.

    Please share the request logs of the main service.

  • User Avatar
    0
    yolier.galan@rockblast.cl created

    Hi, I have changed the browser (Chrome instead of Firefox) and it works fine.

    I hope you can fix the problem with ocelot, or add more documentation on how to replace ocelot with other external proxies or gateways like Traefik or similar.

    thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will give feedback to the development team.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09