From 18fd0a8900a818641428dd54fb11eba2fd4be192 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 17 Sep 2024 22:34:37 +0900 Subject: [PATCH] Fix samchon/nestia#1018: `HttpMigrateRouteFetcher` for React Native. 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", }); ``` --- src/http/HttpMigrateRouteFetcher.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/http/HttpMigrateRouteFetcher.ts b/src/http/HttpMigrateRouteFetcher.ts index 71bd69f..c97072d 100644 --- a/src/http/HttpMigrateRouteFetcher.ts +++ b/src/http/HttpMigrateRouteFetcher.ts @@ -177,10 +177,9 @@ const requestFormDataBody = (input: Record): 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));