From 35f0b12ffdb86602010a8a303f69ad9c31e2d9cc Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 23:00:19 +0000 Subject: [PATCH] fix(internal): make toFile use input file's options (#362) --- src/uploads.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/uploads.ts b/src/uploads.ts index 2398baf3..081827c9 100644 --- a/src/uploads.ts +++ b/src/uploads.ts @@ -102,11 +102,14 @@ export type ToFileInput = Uploadable | Exclude | AsyncIter export async function toFile( value: ToFileInput | PromiseLike, name?: string | null | undefined, - options: FilePropertyBag | undefined = {}, + options?: FilePropertyBag | undefined, ): Promise { // If it's a promise, resolve it. value = await value; + // Use the file's options if there isn't one provided + options ??= isFileLike(value) ? { lastModified: value.lastModified, type: value.type } : {}; + if (isResponseLike(value)) { const blob = await value.blob(); name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file';