Skip to content

Increase size limit for JSON uploads to storage #8356

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

joehan
Copy link
Contributor

@joehan joehan commented Mar 21, 2025

Description

The Storage emulator was applying an artificially low limit on upload size when Content-Type: application/json was set. Fixes #8355

@joehan joehan requested a review from aalej March 21, 2025 21:04
@joehan joehan enabled auto-merge (squash) March 21, 2025 23:03
@aalej
Copy link
Contributor

aalej commented Mar 24, 2025

Tried testing this using https://github.com/aalej/issues-8355. Increasing the size limit removes the PayloadTooLargeError: request entity too large error, however the upload never seems to finish:

$ 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}"'
i  emulators: Starting emulators: storage
i  Running script: 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}"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  126k    0     0  100  126k      0    115  0:18:50  0:18:42  0:00:08     0^C
i  emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown.
i  emulators: Please wait for a clean shutdown or send the SIGINT (Ctrl-C) signal again to stop right now.
i  emulators: Shutting down emulators.
i  storage: Stopping Storage Emulator
⚠  Script exited with signal: SIGINT
i  logging: Stopping Logging Emulator
Using Google Analytics in DEBUG mode. Emulators (+ UI) events will be shown in GA Debug View only.
i  emulators: Shutting down emulators.

@joehan
Copy link
Contributor Author

joehan commented Mar 24, 2025

irebase 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}"

Good catch, i just repro'd this too. Investigating before merging - also need to double check that this is actually new behavior

EDIT: Just tested and this occurs even with an extremely small file - pretty sure we're doing something wrong in the curl, but I'm gonna poke around until I understand exactly whats going on

@mgraczyk
Copy link

@joehan FWIW there is a longstanding, separate bug where the emulator hangs forever when I upload certain files and set the Content-Type header.

This has been an issue for at least a year but I just rerun my tests automatically when this happens, and it never happens with prod GCS so I ignored it.

@mgraczyk
Copy link

@joehan I just looked, the problem is that the handler for the upload POST endpoint tries to read the body here, but it has already been read by express.json here

One fix would be to check for json in here:

As written, it will hang forever in reqBodyToBuffer whenever the body has already been read:

Since express.json writes an empty object {} for non-json Conten-Type headers, you can't just check for typeof request.body === "object", and may need to check the headers before the call to reqBodyToBuffer or something like that.

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

Successfully merging this pull request may close these issues.

PayloadTooLargeError when uploading 130kb json with Content-Type application/json
3 participants