Skip to content

Commit

Permalink
Fix samchon/nestia#1018: HttpMigrateRouteFetcher for React Native.
Browse files Browse the repository at this point in the history
In the React Native, it does not support the `File` class.

Instead, it can compose the `FormData` class instance by appending below primitive object type. The primitive type can replace the `File` class instance in the React Native.

In such reason, changed `HttpMigrateRouteFetcher` logic a little bit for the React Native `File` supporting issue.

```typescript
const form: FormData = new FormData();
form.append("key", {
  uri: "somewhere-uri-address-of-file-location",
  name: "file-name",
  type: "content-media-type",
});
```
  • Loading branch information
samchon committed Sep 17, 2024
1 parent 6b55172 commit 18fd0a8
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/http/HttpMigrateRouteFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,9 @@ const requestFormDataBody = (input: Record<string, any>): FormData => {
const encoded: FormData = new FormData();
const append = (key: string) => (value: any) => {
if (value === undefined) return;
else if (value instanceof Blob)
if (value instanceof File) encoded.append(key, value, value.name);
else encoded.append(key, value);
else encoded.append(key, String(value));
else if (typeof File === "function" && value instanceof File)
encoded.append(key, value, value.name);
else encoded.append(key, value);
};
for (const [key, value] of Object.entries(input))
if (Array.isArray(value)) value.map(append(key));
Expand Down

0 comments on commit 18fd0a8

Please sign in to comment.