Skip to content

Fix file upload regression: restore multipart request data processor#2704

Merged
mbroshi-stripe merged 3 commits intomasterfrom
mbroshi/fix-file-upload
May 6, 2026
Merged

Fix file upload regression: restore multipart request data processor#2704
mbroshi-stripe merged 3 commits intomasterfrom
mbroshi/fix-file-upload

Conversation

@mbroshi-stripe
Copy link
Copy Markdown
Contributor

@mbroshi-stripe mbroshi-stripe commented May 5, 2026

Why?

File uploads to /v1/files broke in v22 (works in v21). When FileResource was
converted from StripeResource.extend({...}) to a class-based pattern in #2619,
the requestDataProcessor = multipartRequestDataProcessor assignment was dropped.

Without it, file upload POST bodies go through queryStringifyRequestData() instead
of multipartDataGenerator(), producing malformed request bodies that the Stripe API
rejects with 400 "Invalid request (check your POST parameters)".

What?

  • Restored requestDataProcessor = multipartRequestDataProcessor on FileResource
  • Added regression test verifying file uploads produce multipart-encoded bodies
    (a Uint8Array containing proper Content-Disposition: form-data headers)

See Also

Changelog

  • Fixed file uploads failing with StripeInvalidRequestError on the /v1/files endpoint since v22.

@mbroshi-stripe mbroshi-stripe marked this pull request as ready for review May 5, 2026 21:01
@mbroshi-stripe mbroshi-stripe requested a review from a team as a code owner May 5, 2026 21:01
@mbroshi-stripe mbroshi-stripe requested review from Copilot, jar-stripe and prathmesh-stripe and removed request for a team May 5, 2026 21:01
Copy link
Copy Markdown
Contributor

@jar-stripe jar-stripe left a comment

Choose a reason for hiding this comment

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

LGTM; please double check that the test is using the correct class before merging

Comment thread test/resources/Files.spec.js Outdated
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

Fixes a regression in the /v1/files resource introduced during the v22 class-based resource migration, where file uploads stopped being encoded as multipart/form-data and were instead URL-encoded.

Changes:

  • Restored requestDataProcessor = multipartRequestDataProcessor on FileResource so file uploads are encoded via multipartDataGenerator() again.
  • Added a regression test asserting that stripe.files.create() produces a multipart-encoded request body (captured as a Uint8Array containing Content-Disposition: form-data).

Reviewed changes

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

File Description
test/resources/Files.spec.js Adds a regression test to ensure file upload bodies are multipart/form-data encoded.
src/resources/Files.ts Re-enables multipart request processing for FileResource uploads.

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

mbroshi-stripe and others added 2 commits May 5, 2026 17:08
Buffer.from().toString() is more idiomatic for Node.js tests and avoids
potential TextDecoder edge cases with binary data.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Committed-By-Agent: claude
The SDK uses TextEncoder/TextDecoder everywhere (not Buffer) for
cross-platform compatibility. Tests should follow the same pattern.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Committed-By-Agent: claude
@mbroshi-stripe mbroshi-stripe enabled auto-merge (squash) May 6, 2026 13:39
@mbroshi-stripe mbroshi-stripe merged commit fe46e5f into master May 6, 2026
11 checks passed
@mbroshi-stripe mbroshi-stripe deleted the mbroshi/fix-file-upload branch May 6, 2026 13:40
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.

3 participants