Repository navigation
feat: Add request header X-Parse-Upload-Mode to identify file upload as binary data via Buffer, Readable, ReadableStream - #2927
Conversation
|
🚀 Thanks for opening this pull request! |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
📝 WalkthroughWalkthroughAdded the header Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/ParseFile.ts (1)
593-596:'stream'header value also applies toBufferuploads — consider a dedicated value or documenting the intent.
saveBinaryhandles bothbufferandstreamformat sources, yetX-Parse-Upload-Modeis always'stream'. For aBufferupload the body is a raw in-memory blob, not a streamed entity. If the Parse Server (or any proxy) ever needs to distinguish the two, it will have no way to do so from this header.If the intent is purely to signal "binary (not base64)", a value like
'binary'would be more accurate for both cases; if the server genuinely needs to distinguish, separate values ('buffer'/'stream') would be cleaner.💡 Option A — single generic value
- 'X-Parse-Upload-Mode': 'stream', + 'X-Parse-Upload-Mode': 'binary',💡 Option B — differentiated values
- 'X-Parse-Upload-Mode': 'stream', + 'X-Parse-Upload-Mode': source.format === 'buffer' ? 'buffer' : 'stream',🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/ParseFile.ts` around lines 593 - 596, The X-Parse-Upload-Mode header is always set to 'stream' even though saveBinary handles both Buffer and stream sources; update the header logic in the saveBinary flow (where headers are built, referencing X-Parse-Upload-Mode and CoreManager.get('APPLICATION_ID')) to use a meaningful value: either a generic 'binary' for all non-base64 uploads or choose differentiated values like 'buffer' vs 'stream' based on the actual input type detected before setting headers. Ensure the chosen value is documented in comments and consistently used wherever saveBinary constructs headers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/__tests__/ParseFile-test.js`:
- Around line 976-996: The test incorrectly checks the JSON request body for the
header; instead mock the binary path and assert it was never used: replace the
inline ajax: () => {} with a jest.fn() mock (e.g., ajaxMock) when calling
CoreManager.setRESTController, call file.save() as before, assert request was
called with the base64 payload, and then assert ajaxMock was not called to
guarantee the binary/upload-mode path was not taken (reference the request mock,
ajax mock, and the ParseFile.save invocation).
---
Nitpick comments:
In `@src/ParseFile.ts`:
- Around line 593-596: The X-Parse-Upload-Mode header is always set to 'stream'
even though saveBinary handles both Buffer and stream sources; update the header
logic in the saveBinary flow (where headers are built, referencing
X-Parse-Upload-Mode and CoreManager.get('APPLICATION_ID')) to use a meaningful
value: either a generic 'binary' for all non-base64 uploads or choose
differentiated values like 'buffer' vs 'stream' based on the actual input type
detected before setting headers. Ensure the chosen value is documented in
comments and consistently used wherever saveBinary constructs headers.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #2927 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 64 64
Lines 6318 6318
Branches 1517 1513 -4
=========================================
Hits 6318 6318 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/__tests__/ParseFile-test.js`:
- Around line 976-996: The test "base64 uploads do not include
X-Parse-Upload-Mode header" is correct as written and requires no code change;
keep the jest mocks and assertions (the ParseFile instantiation and save call,
mocking CoreManager RESTController via request and ajax, and the
expect(request).toHaveBeenCalledWith(...) plus
expect(ajax).not.toHaveBeenCalled()) because using ajax = jest.fn() with
expect(ajax).not.toHaveBeenCalled() is the intended stronger guard proving the
binary/streaming code path (which sets X-Parse-Upload-Mode) was never entered.
# [8.2.0-alpha.2](8.2.0-alpha.1...8.2.0-alpha.2) (2026-02-20) ### Features * Add request header `X-Parse-Upload-Mode` to identify file upload as binary data via `Buffer`, `Readable`, `ReadableStream` ([#2927](#2927)) ([a66bb06](a66bb06))
|
🎉 This change has been released in version 8.2.0-alpha.2 |
# [8.2.0](8.1.0...8.2.0) (2026-02-20) ### Bug Fixes * `Parse.Object.createWithoutData` doesn't preserve object subclass ([#2907](#2907)) ([01dc94d](01dc94d)) * `Parse.Query.and/or/nor` loosing custom class types ([#2903](#2903)) ([89fdb07](89fdb07)) * `Parse.serverURL` not accessible via global `Parse` scope ([#2917](#2917)) ([4e78681](4e78681)) * Cloud trigger type errors for void returns and subclass constructors ([#2904](#2904)) ([de9f56d](de9f56d)) * Missing or incorrect type exports ([#2909](#2909)) ([3caa4ec](3caa4ec)) * Type error in `Parse.Query.equalTo` when matching optional array ([#2901](#2901)) ([8c96da9](8c96da9)) ### Features * Add request header `X-Parse-Upload-Mode` to identify file upload as binary data via `Buffer`, `Readable`, `ReadableStream` ([#2927](#2927)) ([a66bb06](a66bb06)) * Add support for file upload as binary data via `Buffer`, `Readable`, `ReadableStream` ([#2925](#2925)) ([e42caf6](e42caf6))
|
🎉 This change has been released in version 8.2.0 |
Pull Request
Issue
Add request header
X-Parse-Upload-Modeto identify file upload as binary data viaBuffer,Readable,ReadableStream.This new header is needed to distinguish between the new streaming and traditional non-streaming file upload on the Parse Server side. Other ways to distinguish have drawbacks and introduce breaking changes in edge cases. For example, using
Content-Type: application/octet-streamto infer streaming would be a misuse as it should describe the data, not delivery mode.Summary by CodeRabbit
New Features
Tests