fix(blob): normalize contentDisposition to use original filename when addRandomSuffix is enabled#1041
Conversation
… addRandomSuffix is enabled When addRandomSuffix is configured for client uploads, the Blob API returns contentDisposition with the suffixed filename. This fix ensures the SDK always returns the original filename in contentDisposition, consistent with server put(). Fixes vercel#903
|
@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. |
🦋 Changeset detectedLatest commit: bc768a4 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
Fixes an inconsistency in the SDK’s contentDisposition value when the Blob API returns a suffixed pathname (e.g. with addRandomSuffix: true), ensuring the returned contentDisposition filename matches the original requested pathname.
Changes:
- Add a
normalizeContentDisposition()helper and apply it to both single-part and multipartput()result mapping. - Add regression tests for the normalization behavior and update an existing inline snapshot impacted by the normalization.
- Add a patch changeset for
@vercel/blob.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/blob/src/put.ts | Normalizes contentDisposition filename to the original requested pathname (single + multipart paths). |
| packages/blob/src/index.node.test.ts | Adds regression tests and updates an inline snapshot affected by filename normalization. |
| .changeset/fix-blob-client-content-disposition.md | Declares a patch release and documents the behavior change. |
Comments suppressed due to low confidence (1)
packages/blob/src/index.node.test.ts:487
- The
has an onUploadProgress optiontest now returns a snapshot wherecontentDispositionis normalized toprogress.txt, but the mocked API response still returnspathname: "foo.txt". This makes the snapshot internally inconsistent and couples this progress test to the new normalization behavior. Consider using a dedicated mock response for this test wherepathname/contentDispositionmatch the requested pathname (or assertpathnameexplicitly if the mismatch is intentional).
it('has an onUploadProgress option', async () => {
mockClient
.intercept({
path: () => true,
method: 'PUT',
})
.reply(200, () => {
return mockedFileMetaPut;
});
const onUploadProgress = jest.fn();
await expect(
put('progress.txt', 'Test Body', {
access: 'public',
onUploadProgress,
}),
).resolves.toMatchInlineSnapshot(`
{
"contentDisposition": "attachment; filename="progress.txt"",
"contentType": "text/plain",
"downloadUrl": "https://storeId.public.blob.vercel-storage.com/foo-id.txt?download=1",
"etag": ""abc123"",
"pathname": "foo.txt",
"url": "https://storeId.public.blob.vercel-storage.com/foo-id.txt",
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ails Replaces the vague 'Failed to retrieve the client token' message (also fixing the double-space typo) with one that includes the HTTP status code and status text, making auth errors (401, 403) easier to diagnose. Closes vercel#488
…rieval fails" This reverts commit 37df19e.
|
Addressed this by adding a regression that exercises the actual multipart |
Summary
Fixes #903
When
addRandomSuffix: trueis configured for client uploads (upload()), the Vercel Blob API returns acontentDispositionheader that includes the random suffix in the filename (e.g.attachment; filename="img-abc123.jpg"). Server-sideput()withaddRandomSuffix: truecorrectly returns the original filename (e.g.attachment; filename="img.jpg").The inconsistency is in how the API handles the two request types:
put(): sendsx-add-random-suffix: 1header → API returns original filename inContent-Disposition✓upload(): sendsaddRandomSuffix: trueinside the signed client token → API returns suffixed filename inContent-Disposition✗Fix: Added a
normalizeContentDisposition()helper input.tsthat replaces the response filename with the originalpathnamefilename when they differ. Applied to both the regular and multipart code paths increatePutMethod.Changes
packages/blob/src/put.ts— addnormalizeContentDisposition()and apply it to both regular and multipart upload responsespackages/blob/src/index.node.test.ts— add regression tests for the fix; update one pre-existing snapshot that used a mismatched mock (the fix now correctly derivescontentDispositionfrom the original pathname).changeset/fix-blob-client-content-disposition.md— patch changesetTest plan
pnpm testinpackages/blob— all 137 tests passput('foo.txt', body, { addRandomSuffix: true })where API returnspathname: 'foo-abc123.txt'→result.contentDispositionisattachment; filename="foo.txt"put('foo.txt', body, { addRandomSuffix: false })→result.contentDispositionunchanged