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. Home | 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.

6 Likes

Is the 2 mb limit for each file on the asset canister still active ?

I’m encountering this error with no frontend asset canister, just trying to get the “Hello world!” project deployed using Rust.

My structure is like this:

rust_hello
   |_ src
      |_ rust_hello
      |  |_ Cargo.toml
      |  |_ main.rs
      |  |_ rust_hello.did
      |_ rust_hello_assets //not using this for now
   |_ Cargo.toml (and lock)
   |_ dfx.json
   |_ package.json (and lock)
   |_ webpack.config.js

src/rust_hello/Cargo.toml

[package]
name = "rust_hello"
version = "0.1.0"
edition = "2018"

[lib]
path = "main.rs"
crate-type = ["cdylib"]

[dependencies]
ic-cdk = "0.2.4"
ic-cdk-macros = "0.2.4"

src/rust_hello/main.rs

use ic_cdk_macros::*;

#[query]
fn print() {
    ic_cdk::print("Test");
}

src/rust_hello/rust_hello.did

service: {
    "print": () -> () query;
}

proj root toml

[workspace]
members = [
    "src/rust_hello"
]

dfx.json

{
  "version": 1,
  "canisters": {
    "rust_hello": {
      "build": "cargo build --target wasm32-unknown-unknown --package rust_hello",
      "candid": "src/rust_hello/rust_hello.did",
      "wasm": "target/wasm32-unknown-unknown/debug/rust_hello.wasm",
      "type": "custom"
    }
  },
  "networks": {
    "local": {
      "bind": "127.0.0.1:8002",
      "type": "ephemeral"
    }
  }
}
$ dfx start
$ dfx deploy
$ Deploying all canisters.
$ Creating canisters...
$ Creating canister "rust_hello"...
$ Creating the canister using the wallet canister...
$ Creating a wallet canister on the local network.
$ The wallet canister on the "local" network for user "default" is "rwlgt-iiaaa-aaaaa-aaaaa-cai"
$ "rust_hello" canister created with canister id: "rrkah-fqaaa-aaaaa-aaaaq-cai"
$ Building canisters...
$ //build omitted, is successful
$ 

No idea what could be causing the payload to be so large. Seeking a way to debug this, or some clarity. Am just trying to follow the Rust quick start in the developer docs for now.

I’m getting a 403 every time I try to edit my original post for some reason… here is the actual error moment after the successful cargo build:

$ Installing canisters...
$ Installing code for canister rust_hello, with canister_id rrkah-fqaaa-aaaaa-aaaaq-cai
$ The replica returned an HTTP Error: Http Error: status 413 Payload Too Large, content type "text/plain; charset=UTF-8", content: Request 0x3d1159dd50d80118aab5417b323b995a1d0bf6465d8b89a06f7c795a728ad66a is too large. 

@shan Can you run the ic-cdk-optimizer to trim the file size of the rust canister? There are pointers on how to do that here. Will make a note to merge that PR so it’s reflected in the docs.

5 Likes

The latest beta releases of dfx support chunking of large assets and you can try this in 0.7.0-beta.2 We’ll be publishing documentation on this soon. cc @ericswanson did all the amazing work for supporting this feature!

4 Likes

Thanks! I’ll be sure to give that a try once it’s released :slight_smile:

edit: hold, think it’s working now

Ah; might want to note in the documentation that you need to make sure the release folder is created first in the target build output before setting that as an output for tired people like me :stuck_out_tongue:

Edit: deployed! Woo! :partying_face:

1 Like

Yup, looks like a typo in the pull request, thanks for catching it. and awesome!

1 Like

Cool, Im trying it out now.

also will we see a dfx version 1.0 at the genesis? or have you guys built a whole development kit as a canister sitting on the ic or something like that? i know it says that the dfx tool as of now should not be used for production services, im curious what tool will be good for production. is the ic frontend canister guaranteed to support flutter compiled code? should i start building in flutter or wait till genesis to see what is supported?

For anyone else encountering this issue when trying to deploy a wasm32-unknown-unknown target in Rust; I made a very simple build script using cargo-make plugin to both build & optimize the wasm output in one go, commented here.

6 Likes

Is this this the solution we can never have code that is more then 2mb ?

Hey, same problem here, with the rust hello world.

Please pay attention to the circled part if you see it. Just follow the instruction and install ic-cdk-optimizer (and perhaps also put ~/.cargo/bin in your PATH), and then deploy again. It should be a success.

2 Likes