Skip to content

fix(blob): enforce maximumSizeInBytes client-side for multipart uploads#1036

Merged
vvo merged 1 commit intovercel:mainfrom
matingathani:fix/blob-empty-file-and-multipart-size
Apr 2, 2026
Merged

fix(blob): enforce maximumSizeInBytes client-side for multipart uploads#1036
vvo merged 1 commit intovercel:mainfrom
matingathani:fix/blob-empty-file-and-multipart-size

Conversation

@matingathani
Copy link
Copy Markdown
Contributor

@matingathani matingathani commented Apr 1, 2026

Summary

Fixes #873maximumSizeInBytes was not enforced for multipart uploads.

uncontrolledMultipartUpload never checked maximumSizeInBytes. For bodies with a known size (Blob, File, Buffer), a client-side check is now done before the multipart upload begins, avoiding wasted API calls (create + upload parts) that would ultimately be rejected by the server.

Streams are skipped since their size is unknown upfront — enforcement is left to the server.

Also adds maximumSizeInBytes to CommonCreateBlobOptions so it's available to the multipart code path.

Test plan

  • New test: multipart: true + maximumSizeInBytes throws before upload starts
  • New test: stream body with maximumSizeInBytes does not throw client-side

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 1, 2026 21:31
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 1, 2026

🦋 Changeset detected

Latest commit: d91f40c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@vercel/blob Patch
vercel-storage-integration-test-suite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes two @vercel/blob upload issues: (1) missing x-content-length for empty (0-byte) non-stream uploads, and (2) missing maximumSizeInBytes enforcement for multipart uploads, adding tests to cover both behaviors.

Changes:

  • Always send x-content-length for non-stream bodies (including 0-byte Blobs) in requestApi.
  • Enforce maximumSizeInBytes client-side before starting an uncontrolled multipart upload.
  • Add/adjust Node tests to validate the new header behavior and multipart size enforcement.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/blob/src/api.ts Ensures x-content-length is sent for all non-stream bodies, including empty bodies.
packages/blob/src/api.node.test.ts Adds coverage for x-content-length behavior (0-byte Blob + non-empty Blob without progress).
packages/blob/src/multipart/uncontrolled.ts Adds preflight maximumSizeInBytes enforcement before multipart upload creation.
packages/blob/src/helpers.ts Adds maximumSizeInBytes to CommonCreateBlobOptions and documents intended behavior.
packages/blob/src/index.node.test.ts Adds a test asserting multipart put() throws when exceeding maximumSizeInBytes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/blob/src/helpers.ts Outdated
Comment thread packages/blob/src/multipart/uncontrolled.ts Outdated
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 1, 2026

@matingathani is attempting to deploy a commit to the Curated Tests - Permanent E2E Team on Vercel.

A member of the Team first needs to authorize it.

@matingathani
Copy link
Copy Markdown
Contributor Author

Addressed Copilot's review comments in the follow-up commit (ee4224d): changed the options type to CommonCreateBlobOptions & WithUploadProgress to resolve the type mismatch, tightened the JSDoc to accurately reflect multipart-only enforcement, and fixed the empty-string edge case in the body length guard. All 105 tests still passing locally.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vercel-storage-next-integration-test-suite Ready Ready Preview Apr 2, 2026 1:00pm

Request Review

For bodies with a known size (Blob, File, Buffer), check
maximumSizeInBytes before starting the multipart upload. This avoids
creating a multipart upload and uploading parts that will ultimately
be rejected by the server for exceeding the size limit.

Streams are skipped since their size is unknown upfront.

Fixes vercel#873

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vvo vvo force-pushed the fix/blob-empty-file-and-multipart-size branch from d501d0f to d91f40c Compare April 2, 2026 12:58
@vvo vvo changed the title fix(blob): send x-content-length for empty files, enforce maximumSizeInBytes in multipart uploads fix(blob): enforce maximumSizeInBytes client-side for multipart uploads Apr 2, 2026
@vvo
Copy link
Copy Markdown
Member

vvo commented Apr 2, 2026

@matingathani Thanks. We just updated our Blob API to allow for empty files to be uploaded. I kept your addition as for making max size check locally on multipart uploads.

@vvo vvo merged commit d2ea7cf into vercel:main Apr 2, 2026
7 of 10 checks passed
@matingathani matingathani deleted the fix/blob-empty-file-and-multipart-size branch April 16, 2026 00:11
@matingathani
Copy link
Copy Markdown
Contributor Author

Thanks for merging and for the context! Really glad the multipart size check was useful. I'd love to keep contributing to this repo , I am happy to pick up issues or dive into areas where help is needed. Looking forward to learning more about how the Blob API works under the hood.

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.

maximumSizeInBytes not enforced for multipart uploads

3 participants