Skip to content

fix(aws): preserve binary S3 object bodies - #225

Open
kamal wants to merge 2 commits into
vercel-labs:mainfrom
envoy:fix/s3-binary-objects
Open

fix(aws): preserve binary S3 object bodies#225
kamal wants to merge 2 commits into
vercel-labs:mainfrom
envoy:fix/s3-binary-objects

Conversation

@kamal

@kamal kamal commented Sep 4, 2026

Copy link
Copy Markdown

Summary

S3 uploads retain their exact bytes, and HEAD responses preserve the object size required by download clients.

  • Store object payloads as base64 and read PUT and presigned POST uploads as binary data.
  • Finalize HEAD responses with a null body while preserving response and middleware headers. Cancel any discarded response stream.
  • Cover binary uploads through the AWS SDK and HEAD metadata with and without middleware.

Why

S3 object uploads currently pass through Request.text() and Response.text(). Arbitrary binary objects are therefore decoded as UTF-8 and invalid bytes are replaced, corrupting images and other binary files.

An empty streamed HEAD response also causes Bun to replace Content-Length with chunked encoding. Ruby S3 download clients then lack the object size they need. The shared HTTP-layer fix preserves that metadata without sending a response body.

Prior work

This builds on and credits #53 by @zaru, which first identified the binary PUT/GET corruption and proposed base64-backed storage. This version applies that fix to the current S3 route structure, also covers presigned POST uploads and copied objects, names the stored representation body_base64, and exercises the behavior through the real AWS SDK with an SSE-S3 request.

Testing

  • AWS suite: 56 passed, including the real SDK binary-object regression.
  • Core suite: 78 passed, including HEAD Content-Length and null-body assertions with and without middleware and a partNumber=1 query.
  • Core typecheck passes. These checks ran under Node 24.
  • AWS typecheck and lint passed during the original binary-object validation.

Compound Engineering
Codex

@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@kamal is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant