Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: formData bug in react native #1114

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/uploadthing/src/internal/upload.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,28 @@ const uploadWithProgress = (
});

const formData = new FormData();
formData.append("file", rangeStart > 0 ? file.slice(rangeStart) : file);
/**
* iOS/React Native FormData handling requires special attention:
*
* Issue: In React Native, iOS crashes with "attempt to insert nil object" when appending File directly
* to FormData. This happens because iOS tries to create NSDictionary from the file object and expects
* specific structure {uri, type, name}.
*
*
* Note: Don't try to use Blob or modify File object - iOS specifically needs plain object
* with these properties to create valid NSDictionary.
*/
if ("uri" in file) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
formData.append("file", {
uri: file.uri as string,
type: file.type,
name: file.name,
...(rangeStart > 0 && { range: rangeStart }),
} as any);
} else {
formData.append("file", rangeStart > 0 ? file.slice(rangeStart) : file);
}
xhr.send(formData);

return Micro.sync(() => xhr.abort());
Expand Down
Loading