From a414601d500fe945a11b4a4c5e4a84da81718fb3 Mon Sep 17 00:00:00 2001 From: Win Cheng Date: Thu, 11 Sep 2025 13:42:46 -0700 Subject: [PATCH 1/3] fixed multiform passing --- src/utils.ts | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 8bd3e73..b633810 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,32 +5,15 @@ * @param fileFieldName - The field name for the file (defaults to "file") * @returns FormData object ready for upload */ -export function createFileUploadFormData(file: Blob | Buffer, options?: Record, fileFieldName: string = "file"): FormData { +export function createFileUploadFormData(file: Blob | Buffer, body?: Record): FormData { const formData = new FormData(); // Convert Buffer to Blob if needed const fileToAppend = file instanceof Buffer ? new Blob([file]) : file; - formData.append(fileFieldName, fileToAppend); + formData.append("file", fileToAppend); + formData.append("body", JSON.stringify(body)); - // Add options as form fields, handling arrays and objects properly - if (options) { - for (const [key, value] of Object.entries(options)) { - if (value === undefined || value === null) { - continue; // Skip undefined/null values - } - - if (Array.isArray(value)) { - // Convert arrays to JSON strings - formData.append(key, JSON.stringify(value)); - } else if (typeof value === "object") { - // Convert objects to JSON strings - formData.append(key, JSON.stringify(value)); - } else { - // Convert primitives to strings - formData.append(key, String(value)); - } - } - } + console.log("FormData on SDK", formData); return formData; } From d1c23fd0a139ebc36af149e69a9a06138180338f Mon Sep 17 00:00:00 2001 From: Win Cheng Date: Thu, 11 Sep 2025 15:15:18 -0700 Subject: [PATCH 2/3] update test --- src/utils.ts | 2 -- tests/web.test.ts | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index b633810..274e2fd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,8 +13,6 @@ export function createFileUploadFormData(file: Blob | Buffer, body?: Record { }); // Test root_element_selector parameter - test("should work with root_element_selector", async () => { - const result = await client.web.ai_scrape({ - url: TEST_URLS.webpage, - element_prompts: ["Find main content"], - root_element_selector: "body", - }); - - expectSuccess(result); - expectArray(result.data); - }); + // test("should work with root_element_selector", async () => { + // const result = await client.web.ai_scrape({ + // url: TEST_URLS.webpage, + // element_prompts: ["Find main content"], + // root_element_selector: "body", + // }); + + // expectSuccess(result); + // expectArray(result.data); + // }); test("should work with custom root_element_selector", async () => { const result = await client.web.ai_scrape({ From ad577f3f9fd5b0665e2dd27c641e9254c2438a22 Mon Sep 17 00:00:00 2001 From: Win Cheng Date: Fri, 12 Sep 2025 08:22:00 -0700 Subject: [PATCH 3/3] test works, uncommenting now --- tests/web.test.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/web.test.ts b/tests/web.test.ts index 3f2fb64..235d6c6 100644 --- a/tests/web.test.ts +++ b/tests/web.test.ts @@ -160,16 +160,16 @@ describe("AI Scrape API", () => { }); // Test root_element_selector parameter - // test("should work with root_element_selector", async () => { - // const result = await client.web.ai_scrape({ - // url: TEST_URLS.webpage, - // element_prompts: ["Find main content"], - // root_element_selector: "body", - // }); - - // expectSuccess(result); - // expectArray(result.data); - // }); + test("should work with root_element_selector", async () => { + const result = await client.web.ai_scrape({ + url: TEST_URLS.webpage, + element_prompts: ["Find main content"], + root_element_selector: "body", + }); + + expectSuccess(result); + expectArray(result.data); + }); test("should work with custom root_element_selector", async () => { const result = await client.web.ai_scrape({