Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 'Request Entity Too Large' error when POSTing to internal api routes #2507

Open
diemonster opened this issue Apr 7, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@diemonster
Copy link

Describe the bug
I've created a form as a client component in my project that includes file uploads. For context, the uploads are typically screenshots that users submit for support requests through our website.

I can submit the form just fine to an external API using fetch from the client component, but I would rather not have the client sent this form directly for spam/security reasons. As such, I created an api route that I thought I could post to from the client component. It looks like this:

export async function api(request: HydrogenRequest) {
  const formData = await request.formData();

  const res = await fetch(`https://external_api`, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    method: 'POST',
    body: formData,
  });

  const json = await res.json();
  if (!json.errors && json) {
    return new Response(null, {
      status: 200,
    });
  } else {
    return new Response(
      JSON.stringify({error: json.errors ?? 'Unknown error'}),
      {status: 401},
    );
  }
}

However, as soon as I attempt to submit this form to the internal api route, I get an error "Request Entity Too Large". I assume this is a fixed setting somewhere within Hydrogen?

Is there an exposed setting somewhere that I can change? Or is there workaround for this file limit?

@diemonster diemonster added the bug Something isn't working label Apr 7, 2023
@davidhousedev
Copy link

This is a bit of a guess on my part. Is it possible that your cookies header is getting too large? Cookies set on your site would be sent from your site, but I don't think they'd be sent from a different domain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants