2

ASP.NET Core MVC 2

I need to send big raw data (the byte[]). My POST-request contains the Content-Type: application/octet-stream header.

This is the controller action:

[HttpPost]
public async Task<IActionResult> RawBinaryDataManual()
{
  using (var ms = new MemoryStream())
  {
    await Request.Body.CopyToAsync(ms);
    var bytes = ms.ToArray();
    return StatusCode((int) HttpStatusCode.OK);
  }
}

It works fine when I post 22Mb file, but I get the Exception thrown: 'Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException' error if I try to send the 38Mb file.

How can I fix this problem?

UPD
Thanks to phuzi - he wrote the link in the comments which helped to me to solve my problem.

Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
  • Maybe posting the stack trace would also help? – Uwe Keim Jan 15 '18 at 11:50
  • My *Call Stack* window is empty after exception occurs. – Andrey Bushman Jan 15 '18 at 11:54
  • 6
    Possible duplicate of [Increase upload file size in Asp.Net core](https://stackoverflow.com/questions/38698350/increase-upload-file-size-in-asp-net-core) – phuzi Jan 15 '18 at 11:56
  • @phuzi Thank you! The `[DisableRequestSizeLimit]` or `[RequestSizeLimit(1024 * 1024 *1024)] // not more than 1Gb` attributes solved this problem. – Andrey Bushman Jan 15 '18 at 12:04
  • Though keep in mind you are loading the whole file into memory at once here. Better have enough RAM available :) Otherwise, you will need to use Streams. – juunas Jan 15 '18 at 19:29

0 Answers0