5

I have a fetch POST that is sending a large JSON object:

const body = JSON.stringify(largeItem); // 80MB

const request = new Request(uri, {
    mode: 'cors',
    method: 'POST',
    headers: new Headers({ 'Content-Type': 'application/json' }),
    credentials: 'same-origin',
    body
});

const response = await fetch(request);

This results in an error:

source-file.ts:72 Uncaught (in promise) TypeError: Failed to fetch

When I view this request in dev tools it looks incomplete - no request body and most of the request headers are missing. In addition it errors without a status code, instead the status is:

(failed) net::ERR_CONNECTION_RESET

Lots of other GET and POST requests to the same resource with the same credentials work fine. This code works fine with a smaller body.

How do I POST a request with a large (in this case 80MB) JSON body?

Keith
  • 150,284
  • 78
  • 298
  • 434

1 Answers1

2

I think your issue is related to http or the web server (or I guess the browser) Limits

Please read this answer to know what I'm talking about

Can HTTP POST be limitless?.

Louay Al-osh
  • 3,177
  • 15
  • 28
  • 1
    Brilliant, thanks, this was the problem. I expected the server to return a `405` or something like that for requests that are too large, but instead it just rejects the connection entirely. – Keith Jun 01 '20 at 21:32