Fix upload size limit: add BODY_SIZE_LIMIT env and error handling
Deploy to LXC / deploy (push) Successful in 21s

- Added BODY_SIZE_LIMIT=52428800 (50MB) to .env.example
- handleError in hooks catches body size exceeded and returns friendly message
- Client-side file size check on image upload input (alerts before submit)
- adapter-node uses BODY_SIZE_LIMIT env var (default was 512KB)

To fix: add BODY_SIZE_LIMIT=52428800 to .env on the server and restart.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-09 14:15:36 +07:00
parent 50689c46e5
commit bb8a96d281
3 changed files with 23 additions and 1 deletions
+15 -1
View File
@@ -1,6 +1,20 @@
import type { Handle } from '@sveltejs/kit';
import type { Handle, HandleServerError } from '@sveltejs/kit';
import { validateSession, setSessionCookie, deleteSessionCookie } from '$lib/server/auth/index.js';
export const handleError: HandleServerError = async ({ error }) => {
const message = error instanceof Error ? error.message : 'Unknown error';
// Body size limit exceeded
if (message.includes('exceeds limit')) {
return {
message: 'File too large. Maximum upload size is 50MB.'
};
}
console.error('Unhandled error:', error);
return { message: 'An unexpected error occurred.' };
};
export const handle: Handle = async ({ event, resolve }) => {
const token = event.cookies.get('session');