fix(blob): enforce maximumSizeInBytes client-side for multipart uploads#1036
Conversation
🦋 Changeset detectedLatest commit: d91f40c The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
There was a problem hiding this comment.
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-lengthfor non-stream bodies (including 0-byte Blobs) inrequestApi. - Enforce
maximumSizeInBytesclient-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.
|
@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. |
|
Addressed Copilot's review comments in the follow-up commit (ee4224d): changed the options type to |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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>
d501d0f to
d91f40c
Compare
|
@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. |
|
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. |
Summary
Fixes #873 —
maximumSizeInByteswas not enforced for multipart uploads.uncontrolledMultipartUploadnever checkedmaximumSizeInBytes. 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
maximumSizeInBytestoCommonCreateBlobOptionsso it's available to the multipart code path.Test plan
multipart: true+maximumSizeInBytesthrows before upload startsmaximumSizeInBytesdoes not throw client-side🤖 Generated with Claude Code