Streaming an upload into sharp saved me about 9% of peak memory, not the order of magnitude people expect. Eight parallel uploads of a 65.5 MB PNG peaked at 1,533 MB when I buffered them and 1,398 MB when I piped them. The same eight uploads were refused at 85 MB by checking Content-Length before reading a byte. The cheap check beat the clever one.
Below is the server I tested, the five cases, and what to put at the front of your upload route.
Why would streaming not save memory?
Decoding dominates. A 65.5 MB PNG is 8000 × 6250 pixels, and in my companion measurement of a 50 MP decode a full decode of that size needs about 150 MB of raw pixels. Eight of those in flight is over a gigabyte, whether the compressed bytes arrived in one Buffer or in chunks.…