Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mgraczyk opened this issue Mar 21, 2025 · 0 comments · May be fixed by #8356
Open

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

mgraczyk opened this issue Mar 21, 2025 · 0 comments · May be fixed by #8356

Comments

@mgraczyk
Copy link

mgraczyk commented Mar 21, 2025

[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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants