0

I have an POST call in my API that takes some data, turns it into a docx file, turns the file into a byte array, and then returns that file using File() in the response to the front end for downloading. It works great, but lately the size of the file is starting to grow larger as more information is added, and we are now getting failures.

The API return looks like this:

byte[] file = makeNewDocx(_data);
return File(file, "application/vnd.openxmlformats-officedocument.wordprocessingml.document");

I read that there is a .NET variable that restricts how much data is being sent back to the front end, but I haven't found any documentation on that.

Anyone ever dealt with something like this?

zach
  • 61
  • 1
  • 6
  • 2
    "and we are now getting failures." - what _kind_ of failures? that's an important piece of information to debug the problem. also: how big are the files? – Franz Gleichmann May 11 '21 at 18:15
  • You might be running in to memory limitations. Have you tried streaming the binary data instead of returning it as a byte[]? – just.another.programmer May 11 '21 at 18:20
  • I should have clarified that, thanks for pointing that out Franz. Its a Failed to load resource. status 502 error. The files can can range in size but generally start to fail to return around 16-20MB. When there are a lot of images in the docx file, it can be as large as 70MB. – zach May 11 '21 at 18:22
  • Failed to load resource sounds like you're behind a load balancer and this is the error of the load balancer, not the error of your asp.net app. There should be an exception in the logs too. – Christoph Lütjen May 11 '21 at 19:07

1 Answers1

1

In ASP.Net framework, there was a property called maxRequestLength. I guess there is something similar in ASP.Net Core called as maxallowedcontentlength.

This earlier question may help: Increase upload file size in Asp.Net core

You may also consider using compression. https://learn.microsoft.com/en-us/aspnet/core/performance/response-compression?view=aspnetcore-5.0

Gopal
  • 46
  • 4
  • 1
    Thanks Gopal. It looks like MaxAllowedContentLength may be for uploads rather than downloads/responses, but I am looking into that. – zach May 12 '21 at 15:32