diff --git a/src/utils.ts b/src/utils.ts index 8bd3e73..274e2fd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,32 +5,13 @@ * @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); - - // 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)); - } - } - } + formData.append("file", fileToAppend); + formData.append("body", JSON.stringify(body)); return formData; } diff --git a/tests/web.test.ts b/tests/web.test.ts index 49fb077..235d6c6 100644 --- a/tests/web.test.ts +++ b/tests/web.test.ts @@ -5,7 +5,7 @@ const TEST_URLS = { image: "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png", pdf: "https://www.w3.org/WAI/WCAG21/working-examples/pdf-table/table.pdf", audio: "https://jigsawstack.com/preview/stt-example.wav", - webpage: "https://example.com", + webpage: "https://www.google.com", newsWebpage: "https://news.ycombinator.com", };