0

I'm trying to generate pdf,but after like the 5th page header and footer display http error 400-bad request-request header to long. is there anyway to solve this problem? a response header can look like this

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: // i hid the adress
Cache-Control: no-store, no-cache
Content-Disposition: attachment; filename=Utskrift.pdf
Content-Length: 162568
Content-Type: application/pdf
Date: Tue, 25 Oct 2022 08:57:16 GMT
Expires: -1
Pragma: no-cache
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Roe
  • 633
  • 2
  • 14
  • Why do you have such a large header in your request? I'm guessing [this answer](https://stackoverflow.com/a/43091096/3181933) is for IIS (which is probably what you're using?) and suggests that the default header size limit is 65 KB. That's pretty big. – ProgrammingLlama Oct 25 '22 at 09:08

1 Answers1

0

The length you are trying to send is very large to be handled. It is like overdosing the request header. What you can do is, you can consider to break it in to chunks (smaller sizes), and send them separately until you gather all the file size on the endpoint you are sending.

  • Hmm could you give an example in code how one could do that? i think i understand what you are saying and that sounds like a resonable solution, i guess that would be handled from the frontend Angular before i send in the request to my API? or is it the answer that is to big? and i have to do the changes on my backend in the API before sending the files? – Stefan Fernström Oct 25 '22 at 11:23
  • this is how the method looks when i send the file back to frontend/client @Ediz ` private HttpResponseMessage GetHttpResponseMessage(byte[] content, string fileName) { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new ByteArrayContent(content); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = $"{fileName}.pdf" }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); return response; }` – Stefan Fernström Oct 25 '22 at 11:44
  • Check the link I provided, it may help to understand the way how to deal with it. Mind that this isn't the exact answer to it, but it may help you to lead the way: [link](https://knickrehm.dev/transferring-large-files-in-typescript-using-streams/) – Ediz Suleyman Oct 25 '22 at 14:53