feat: support react native blob objects#5764
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request adds support for React Native blob objects to enable proper handling of file uploads in React Native environments. React Native uses a special "blob" object structure with a uri field that differs from standard web Blob objects.
Key changes:
- Added two new utility functions
isReactNativeBlobandisReactNativefor detecting React Native blob objects and environment - Modified
toFormDatahelper to handle React Native blobs by checking for React Native FormData and blob objects before processing
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/utils.js | Added isReactNativeBlob and isReactNative utility functions to detect React Native blob objects and environment, exported them in the utils module |
| lib/helpers/toFormData.js | Added conditional logic to append React Native blob objects directly when in a React Native environment |
|
closing as this is stale, please re-open if you would like to have me review |
|
Do you think we should change sth? @jasonsaayman |
|
sorry @moh3n9595 i may have closed this too hastily, could you please add unit tests for the changes then i think we can look to merge |
There was a problem hiding this comment.
2 issues found across 3 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="lib/utils.js">
<violation number="1" location="lib/utils.js:201">
P2: Guard against null/undefined before accessing `getParts`; the current implementation throws when `formData` is missing.</violation>
</file>
<file name="lib/helpers/toFormData.js">
<violation number="1" location="lib/helpers/toFormData.js:172">
P1: React Native blob check is inside the `!path` condition, so it only works for root-level properties. Nested blobs (e.g., `{ nested: { file: { uri: '...' } } }`) will be recursed into instead of being appended directly, since `isVisitable` returns true for plain objects. Consider moving this check outside the `if (value && !path && typeof value === 'object')` block, or adding a similar check before the `isVisitable` check.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
I’ve added unit tests to cover the new React Native blob support. |
Add support for React Native "blob"s (objects with an
urifield, React Native FormData implementation can be able to detect and upload them directly from filesystem).