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

seemusPRO

4 days 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 = `<br><br><p style="font-family: Arial, sans-serif; font-size: 14px; color: #000;">Signature</p>

`;

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: `

<p>Hi ${firstName},</p>

${welcomeText}

<p><strong>Your Score:</strong> ${score}</p>

<strong>Your details:</strong></p>

<strong>Your Name:</strong> ${firstName} ${lastName}<br/>

<strong>Company:</strong> ${companyName}<br/>

<strong>Job Role:</strong> ${jobRole}<br/>

<strong>Company Size:</strong> ${companySize}<br/>

<strong>Email:</strong> ${email}</p>

${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: `

<p><strong>Name:</strong> ${firstName} ${lastName}</p>

<p><strong>Company:</strong> ${companyName}</p>

<p><strong>Job Role:</strong> ${jobRole}</p>

<p><strong>Company Size:</strong> ${companySize}</p>

<p><strong>Email:</strong> ${email}</p>

<p><strong>Score:</strong> ${score}</p>

${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

2 Replies

4 days 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.


loudbook

https://svelte.dev/docs/kit/adapter-node#environment-variables-body-size-limitAs 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.

seemusPRO

3 days 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 3 days ago