@@ -88,7 +88,7 @@ export type ToFileInput = Uploadable | Exclude<BlobPart, string> | AsyncIterable
88
88
89
89
/**
90
90
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
91
- * @param bits the raw content of the file. Can be an {@link Uploadable}, {@link BlobPart}, or {@link AsyncIterable} of {@link BlobPart}s
91
+ * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobPart}, or {@link AsyncIterable} of {@link BlobPart}s
92
92
* @param {string= } name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
93
93
* @param {Object= } options additional properties
94
94
* @param {string= } options.type the MIME type of the content
@@ -100,6 +100,9 @@ export async function toFile(
100
100
name ?: string | null | undefined ,
101
101
options : FilePropertyBag | undefined = { } ,
102
102
) : Promise < FileLike > {
103
+ // If it's a promise, resolve it.
104
+ value = await value ;
105
+
103
106
if ( isResponseLike ( value ) ) {
104
107
const blob = await value . blob ( ) ;
105
108
name ||= new URL ( value . url ) . pathname . split ( / [ \\ / ] / ) . pop ( ) ?? 'unknown_file' ;
@@ -121,10 +124,7 @@ export async function toFile(
121
124
return new File ( bits , name , options ) ;
122
125
}
123
126
124
- async function getBytes ( value : ToFileInput | PromiseLike < ToFileInput > ) : Promise < Array < BlobPart > > {
125
- // resolve input promise or promiselike object
126
- value = await value ;
127
-
127
+ async function getBytes ( value : ToFileInput ) : Promise < Array < BlobPart > > {
128
128
let parts : Array < BlobPart > = [ ] ;
129
129
if (
130
130
typeof value === 'string' ||
0 commit comments