# Uploads that don’t grow server memory

> Streaming multipart uploads straight to S3 with multer-s3, and committing metadata only after S3 acknowledges.

Canonical: https://pshah.fun/notes/zero-buffer-uploads-to-s3
Last updated: 2026-10-21

Published 28 September 2026, updated 21 October 2026. Tags: Cloud, Node.js, Storage.

## In short

Stream uploads to S3 instead of buffering them: with multer-s3, memory use tracks the chunk size, not the file size. Write the database record only after S3 confirms every file, so a dropped connection leaves at worst an orphaned object, never a record pointing at nothing.

multer.memoryStorage() holds every file in the Node.js heap until the request finishes. With concurrent large uploads that is a straight path to an out-of-memory crash. Streaming storage pipes each chunk from the socket to S3 as it arrives, so memory use tracks the chunk size, not the file size.

### Upload

1. Multipart request
2. Multer filter (`image/*, 25 MB`)
3. multer-s3 (`UUID key`)
4. S3 ack
5. Image.insertMany()

## Why write metadata only after S3 confirms?

The metadata write happens after S3 confirms every file. If the connection drops mid-upload, there is no database row pointing at an object that doesn’t exist. The worst case is an orphaned object in S3, which a lifecycle rule can clean up, rather than a broken record the UI tries to render.

## How does the browser read from a private bucket?

With Block Public Access on, the browser can’t load objects directly. A /media/:id route looks up the key and streams GetObject back through the server’s IAM role with the stored Content-Type. The UI tries the direct URL first and falls back to the proxy.

Next step: presigned PUT URLs, so the browser uploads straight to S3 and the server only issues permissions and records metadata.

Based on: Cloud Media Hub repository: server.js, ARCHITECTURE.md.

Project: [Cloud Media Hub case study](https://pshah.fun/projects/cloud-media-hub), [source on GitHub](https://github.com/pshah-lab/aws-s3-mongodb-media-hub)

## Related

- [All engineering notes](https://pshah.fun/notes)
