Skip to content

PayloadTooLargeError when uploading 130kb json with Content-Type application/json #8355

Open
@mgraczyk

Description

@mgraczyk

[REQUIRED] Environment info

firebase-tools:
13.35.1

Platform:
macOS 13.7.4

[REQUIRED] Test case

# Generate a 130kb json file
printf '{"k":"%s"}' "$(head -c 130000 < /dev/zero | tr '\0' 'a')" > large.json
# Run the emulator without the Content-Type header, this works
firebase emulators:exec --log-verbosity DEBUG --only storage -- 'curl "localhost:9199/upload/storage/v1/b/bucket/o?name=test&uploadType=media" -d "@large.json" -o /dev/null -w "%{http_code}"'
# ...
200✔  Script exited successfully (code 0)
# Run the same request with Content-Type header set to application/json
firebase emulators:exec --log-verbosity DEBUG --only storage -- 'curl "localhost:9199/upload/storage/v1/b/bucket/o?name=test&uploadType=media" -d "@large.json" -H "Content-Type: application/json" -o /dev/null -w "%{http_code}"'
# ...
413PayloadTooLargeError: request entity too large

[REQUIRED] Steps to reproduce

Run the test case above.

[REQUIRED] Expected behavior

A json object uploaded with the content-type set should be successful, with a 200 status response and the object created.

This should work because in production Cloud Storage, uploading with the content-type header set is the preferred way to ensure that HTTP responses from the bucket use the same content-type header. This is important for serving and metadata tracking.

[REQUIRED] Actual behavior

Uploading with "content-type: application/json" fails because the request size limit is 102400 bytes, which is the default.

The default is set here in server.ts:

app.use(
express.json({
type: ["application/json"],
}),
);

This should either be increased, or if the upload endpoint is hit with the content type header, the emulator should respond with a more informative error message like "Json content types not supported for emulator uploads".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions