Kyle
Kyle

Reputation: 1578

How to increase request size made to api/+server.js

So, I'm trying to send a 10MB (it has to be) request to +server.js in Svelte, the issue is, if the request is bigger than a peanut I get 413ed, I've tried setting up the BODY_SIZE_LIMIT=50000000 (<50MB) in the .env , but it doesn't work it still gives me 413, I've tried looking for it, the only thing I found were the PRs that introduced this limitation (we could handle it with content-length anyway)

Where I found BODY_SIZE_LIMIT in the docs:

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

The PR that gave birth to it:

https://github.com/sveltejs/kit/issues/6542

TLDR: this => app.use(bodyParser.json({ limit: '50mb' })); but in Svelte and Vite

Help me and you get big smooch, Thanks

Svelte.config.js

import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/kit/vite';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    // Consult https://kit.svelte.dev/docs/integrations#preprocessors
    // for more information about preprocessors
    preprocess: vitePreprocess(),

    kit: {
        adapter: adapter()
    }
};

export default config;

.env

BODY_SIZE_LIMIT=50000000

Dependencies

"@playwright/test": "^1.28.1",
"@sveltejs/adapter-auto": "^1.0.0",
"@sveltejs/kit": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte3": "^4.0.0",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.8.1",
"svelte": "^3.54.0",
"svelte-check": "^2.9.2",
"tslib": "^2.4.1",
"typescript": "^4.9.3",
"vite": "^4.0.0",
"vitest": "^0.25.3"

Upvotes: 2

Views: 1988

Answers (3)

Alexander Suraphel
Alexander Suraphel

Reputation: 10623

This worked for me.

export BODY_SIZE_LIMIT=0; npm run build;

Upvotes: 0

Mike Casan Ballester
Mike Casan Ballester

Reputation: 1770

For those using PM2, it is similar:

BODY_SIZE_LIMIT=0 ORIGIN=https://myapp.com pm2 restart /var/www/build/index.js --name 'myapp' --update-env

For me, it did not work setting the variable in .env.

Do not forget to set up the client_max_body_size 100M; in nginx conf file server{} block. More details here.

More info about BODY_SIZE_LIMIT in Svelte doc

Upvotes: 0

Arava Sai teja
Arava Sai teja

Reputation: 1

after running build command try running the command in wsl(ubuntu) terminal - BODY_SIZE_LIMIT=0 node build

Upvotes: 0

Related Questions