Azure ASP.NET Core 8 Web API : upload data

108 Views Asked by At

My environment is:

  • .NET 8
  • EF Core 8
  • c# lang version 12

I have an API which receives image from AXIS camera. The Axis camera is located on the roadside and has a 4G connection to the internet.

My API controller code looks like this:

[HttpPost]
[ApiKey]
public async Task<IActionResult> AddPassage(CancellationToken cancellationToken)
{
    Stream requestBody = new MemoryStream();

    await Request.Body.CopyToAsync(requestBody, cancellationToken);

    var queryString = Guard.Against.NullOrEmpty(Request.QueryString.Value);
    var header = Guard.Against.NullOrEmpty(Request.Headers.ContentDisposition.ToString());

    var command = new CreatePassageCommand(requestBody,
        queryString, header);

    var result = await _sender.Send(command, cancellationToken);

    if (result.IsFailure)
    {
        return BadRequest(result.Error);
    }

    return Ok();
}

When an image is received, it is copied to the blob storage and a record in the database is created.

When I run my code from VS 2022, all images from the AXIS camera are successfully received and saved in blob storage.

But when I deploy my API to Azure, only a small amount of images are received. My API is connected to Application Insights, and there is a bunch of exceptions:

System.OperationCanceledException:

at System.Threading.CancellationToken.ThrowOperationCanceledException (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.IO.Pipelines.Pipe.GetReadAsyncResult (System.IO.Pipelines, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51)
at System.IO.Pipelines.PipeReader+d__16`1.MoveNext (System.IO.Pipelines, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream+d__11.MoveNext (Microsoft.AspNetCore.Server.IIS, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) ...

And also exceptions with message

The client has disconnected An operation was attempted on a nonexistent network connection. (0x800704CD)

and a call stack of:

Microsoft.AspNetCore.Connections.ConnectionResetException:

at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext+d__454.MoveNext (Microsoft.AspNetCore.Server.IIS, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.IO.Pipelines.Pipe.GetReadResult (System.IO.Pipelines, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51) at System.IO.Pipelines.Pipe.GetReadAsyncResult (System.IO.Pipelines, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51) at System.IO.Pipelines.PipeReader+d__16`1.MoveNext (System.IO.Pipelines, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream+d__11.MoveNext (Microsoft.AspNetCore.Server.IIS, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)

Maybe someone of you also has had similar problems? Or maybe someone has a solution to my problem or maybe you can share useful links how to solve my problem?

Thank you.

0

There are 0 best solutions below