413 (Content Too Large) - When sending email and attachment via Resend
seemus
PROOP

a year ago

I'm receiving a "413 (Content Too Large)" on a Email send when using Resend API. This works ok from my Desktop Localhost but not from Railway.

Im using SvelteKit 4, here is the API code:

import { RESEND_API } from '$env/static/private';

export async function POST({ request }) {

const data = await request.json();

const {

firstName,

lastName,

companyName,

jobRole,

companySize,

email,

score,

pdfAttachment,

welcomeText,

} = data;

const Signature = `Signature

`;

const UserResponse = await fetch('https://api.resend.com/emails', {

method: 'POST',

headers: {

Authorization: Bearer ${RESEND_API},

'Content-Type': 'application/json'

},

body: JSON.stringify({

from: 'hello@mydomain.com',

to: email,

subject: 'Your Report',

html: `

${welcomeText}

Your details:

Your Name: ${firstName} ${lastName}

Company: ${companyName}

Job Role: ${jobRole}

Company Size: ${companySize}

Email: ${email}

${Signature}

`,

attachments: [

{

filename: pdfAttachment.name,

content: pdfAttachment.content, // Base64 without prefix

type: 'application/pdf'

}

]

})

});

const BusinessResponse = await fetch('https://api.resend.com/emails', {

method: 'POST',

headers: {

Authorization: Bearer ${RESEND_API},

'Content-Type': 'application/json'

},

body: JSON.stringify({

from: 'hello@mydomain.com',

to: 'hello@mydomain.com',

subject: Report: ${companyName},

html: `

${Signature}

`,

attachments: [

{

filename: pdfAttachment.name,

content: pdfAttachment.content, // Base64 without prefix

type: 'application/pdf'

}

]

})

});

if (!UserResponse.ok) {

const error = await UserResponse.text();

console.log("Error: ", JSON.stringify({ error }))

return new Response(JSON.stringify({ error }), { status: 500 });

}

return new Response(JSON.stringify({ status: 'sent' }), { status: 200 });

}

I am not getting any build errors. The console shows: start.6590e6fc.js:1

POST https://www.mydomain.com/api/send-email 413 (Content Too Large)

As far as I can see there are no reasons for Resend to create this error. And I can't see where Railway would have any limitations.

The filesize of the PDF (converted to Base64) is less than 900k

Any help would be gratefully received.

Solved$10 Bounty

Pinned Solution

a year ago

https://svelte.dev/docs/kit/adapter-node#environment-variables-body-size-limit

As per the docs, the default maximum file size for the Svelte node adapter is 512kb.

To change this, just set the variable BODY_SIZE_LIMIT to something like 1M for 1 megabyte, or Infinity if you want to disable it entirely.

2 Replies

a year ago

https://svelte.dev/docs/kit/adapter-node#environment-variables-body-size-limit

As per the docs, the default maximum file size for the Svelte node adapter is 512kb.

To change this, just set the variable BODY_SIZE_LIMIT to something like 1M for 1 megabyte, or Infinity if you want to disable it entirely.


samgordon

<https://svelte.dev/docs/kit/adapter-node#environment-variables-body-size-limit> As per the docs, the default maximum file size for the Svelte node adapter is 512kb. To change this, just set the variable `BODY_SIZE_LIMIT` to something like `1M` for 1 megabyte, or `Infinity` if you want to disable it entirely.

seemus
PROOP

a year ago

Thanks, this worked when I set Infinity, so I can always dial that back if I want to minimize the size.


Status changed to Solved chandrika 12 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...