Http Error: status 413 Payload Too Large

I’m getting the following error message after dfx deploy:

Deploying all canisters.
All canisters have already been created.
Building canisters...
Building frontend...
Installing canisters...
Installing code for canister hosting, with canister_id rwlgt-iiaaa-aaaaa-aaaaa-cai
The replica returned an HTTP Error: Http Error: status 413 Payload Too Large, content type "text/plain; charset=UTF-8", content: Request 0xaf1d8dadf3f3c3faf56469c81b8806c9acfe09b8f8e1b92c3854e6a86ad7729e is too large.

This is my dfx.json:

  "canisters": {
    "hosting": {
      "frontend": {
        "entrypoint": "src/hosting/entrypoint/index.js"
      },
      "source": [
        "dist/hosting/",
        "dist/build/"
      ],
      "type": "assets"
    }
  },
  "defaults": {
    "build": {
      "packtool": ""
    }
  },
  "dfx": "0.6.16",
  "networks": {
    "ic": {
      "providers": [
        "https://gw.dfinity.network"
      ],
      "type": "persistent"
    },
    "local": {
      "bind": "127.0.0.1:8000",
      "type": "ephemeral"
    }
  },
  "version": 1
}

That said, the directory is not large:

 16K	dist/hosting/
 31M	dist/build/

What am I doing wrong?

Thank you!

FYI, the same on the ic:

$ dfx deploy --network=ic
Deploying all canisters.
Creating canisters...
Creating canister "hosting"...
"hosting" canister created on network "ic" with canister id: "lfvrz-miaaa-aaaab-aaaoa-cai"
Building canisters...
Building frontend...
Installing canisters...
Installing code for canister hosting, with canister_id lfvrz-miaaa-aaaab-aaaoa-cai
The replica returned an HTTP Error: Http Error: status 413 Payload Too Large, content type "text/plain; charset=UTF-8", content: Request 0x8b9216723a32e064d70bbcd4df766c040fc3808a9454c1d2cae2c331964a5a2c is too large.

cf. Developer Release Notes :: Internet Computer

To improve security, performance, and flexibility, there’s a 2MB restriction of the size of update messages. In most cases, this restriction should not prevent you from building and deploying applications to run on the Internet Computer. However, if you find this limitation hinders your ability to design and deploy canisters, contact DFINITY support with details about your use case and for help resolving the issue.

Maybe your canister code or front-end is too big?

Thank you for answer.

Thank you for pointing this out.

Yes, it’s ~31MB:

$ du -sh dist
 31M	dist

Honestly, I think that 2MB is definitely too small even for a very simple frontend or preloaded storage, especially considering that canisters can maintain up to 4GB of memory pages.

The 2MB limit is for individual files, not the whole directory. You can upload around 2GB of data (not the full 4GB because of GC) to the asset canister, as long as each file is smaller than 2MB.

The current workaround is to implement chunking in the frontend code. But I agree this should be done somewhere at the platform level.

4 Likes