2

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"
H.B.
  • 166,899
  • 29
  • 327
  • 400
Kyle
  • 1,568
  • 2
  • 20
  • 46
  • DId you try what the docs say past the 2nd sentence? "You can disable this option with a value of 0 and implement a custom check in handle if you need something more advanced." – Samathingamajig Feb 03 '23 at 08:47
  • Yes, It behaves the same way when `BODY_SIZE_LIMIT = 0` it still maintains the 512KB size limit – Kyle Feb 03 '23 at 11:33
  • 2
    Looks like `BODY_SIZE_LIMIT` is meant to work with `adapter-node` and yet you're using `adapter-auto`. Perhaps switching explicitly to `adapter-node` will solve your issue? – Thomas Hennes Feb 03 '23 at 13:05
  • 1
    In dev mode I can send large files without issue. How are you sending the files in the first place? In case you try to send them as JSON, you should not be doing that. For deployment it depends on the environment and the `.env` file will not necessarily be loaded (as pointed out by Thomas Hennes). – H.B. Feb 03 '23 at 16:41
  • What @ThomasHennes said actually works, do you want to make that into an answer then I'll accept it – Kyle Feb 06 '23 at 11:31

3 Answers3

0

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

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 23 '23 at 00:23
0

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

Mike Casan Ballester
  • 1,690
  • 19
  • 33
0

This worked for me.

export BODY_SIZE_LIMIT=0; npm run build;
Alexander Suraphel
  • 10,103
  • 10
  • 55
  • 90