NextJS body exceed limit when content sent in body is under limit.

I am sending a photo through TRPC that is then being uploaded to a server. Everything is working except sometimes it exceeds the body limit of nextjs api calls even tho I know the image is less than the limit.
const size = image.size / 1024;
console.log(size);
if (size >= 4096) {
console.log("Error, image to large");
return;
}
const foundText = await image.arrayBuffer();
console.log("NewSize", foundText.byteLength / 1024);
const uint = new Uint8Array(foundText);
console.log("BlogStringw", uint.length / 1024); // Shows the correct size, if I upload a 3mb file it shows its 3000kb.

upload(uint, false, image.type);
setImage(null);
setIsDragging(false);

const size = image.size / 1024;
console.log(size);
if (size >= 4096) {
console.log("Error, image to large");
return;
}
const foundText = await image.arrayBuffer();
console.log("NewSize", foundText.byteLength / 1024);
const uint = new Uint8Array(foundText);
console.log("BlogStringw", uint.length / 1024); // Shows the correct size, if I upload a 3mb file it shows its 3000kb.

upload(uint, false, image.type);
setImage(null);
setIsDragging(false);

export const config = { // Config for bodyparser it is working
api: {
bodyParser: {
sizeLimit: "8mb", // Set desired value here
},
},
};
export const config = { // Config for bodyparser it is working
api: {
bodyParser: {
sizeLimit: "8mb", // Set desired value here
},
},
};
Errors: POST http://localhost:3000/api/trpc/images.create?batch=1 413 (Body exceeded 8mb limit) which obviously errors TRPC.
3 Replies
benten
benten2y ago
Had this issue ourselves, the limit is far lower than 8mb
peternovak
peternovak13mo ago
How did you guys solve this one? I just faced this problem myself, and wonder where I should add this configuration so I don't need to do it for all endpoints
Want results from more Discord servers?
Add your server