File tree 2 files changed +13
-3
lines changed
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -107,8 +107,10 @@ export async function toFile(
107
107
// If it's a promise, resolve it.
108
108
value = await value ;
109
109
110
- // Use the file's options if there isn't one provided
111
- options ??= isFileLike ( value ) ? { lastModified : value . lastModified , type : value . type } : { } ;
110
+ // If we've been given a `File` we don't need to do anything
111
+ if ( isFileLike ( value ) ) {
112
+ return value ;
113
+ }
112
114
113
115
if ( isResponseLike ( value ) ) {
114
116
const blob = await value . blob ( ) ;
@@ -126,7 +128,7 @@ export async function toFile(
126
128
127
129
name ||= getName ( value ) ?? 'unknown_file' ;
128
130
129
- if ( ! options . type ) {
131
+ if ( ! options ? .type ) {
130
132
const type = ( bits [ 0 ] as any ) ?. type ;
131
133
if ( typeof type === 'string' ) {
132
134
options = { ...options , type } ;
Original file line number Diff line number Diff line change @@ -54,4 +54,12 @@ describe('toFile', () => {
54
54
const file = await toFile ( input ) ;
55
55
expect ( file . name ) . toEqual ( 'uploads.test.ts' ) ;
56
56
} ) ;
57
+
58
+ it ( 'does not copy File objects' , async ( ) => {
59
+ const input = new File ( [ 'foo' ] , 'input.jsonl' , { type : 'jsonl' } ) ;
60
+ const file = await toFile ( input ) ;
61
+ expect ( file ) . toBe ( input ) ;
62
+ expect ( file . name ) . toEqual ( 'input.jsonl' ) ;
63
+ expect ( file . type ) . toBe ( 'jsonl' ) ;
64
+ } ) ;
57
65
} ) ;
You can’t perform that action at this time.
0 commit comments