@@ -40,21 +40,23 @@ export const upload = (
4040 }
4141
4242 var formData = new FormData ( ) ;
43- let i : keyof typeof uploadOptions ;
44- for ( i in uploadOptions ) {
45- const param = uploadOptions [ i ] ;
46- if ( typeof param !== "undefined" ) {
47- if ( typeof param === "string" || typeof param === "boolean" ) {
48- formData . append ( i , String ( param ) ) ;
49- }
50- else if ( Array . isArray ( param ) ) {
51- formData . append ( i , JSON . stringify ( param ) ) ;
52- }
53- else if ( typeof param === "object" && ! ( param instanceof File || param instanceof Blob ) ) {
54- formData . append ( i , JSON . stringify ( param ) ) ;
43+ let key : keyof typeof uploadOptions ;
44+ for ( key in uploadOptions ) {
45+ if ( key ) {
46+ if ( key == "file" && typeof uploadOptions . file != "string" ) {
47+ formData . append ( 'file' , uploadOptions . file , String ( uploadOptions . fileName ) ) ;
48+ } else if ( key == "tags" && Array . isArray ( uploadOptions . tags ) ) {
49+ formData . append ( 'tags' , uploadOptions . tags . join ( "," ) ) ;
50+ } else if ( key == "responseFields" && Array . isArray ( uploadOptions . responseFields ) ) {
51+ formData . append ( 'responseFields' , uploadOptions . responseFields . join ( "," ) ) ;
52+ } else if ( key == "extensions" && Array . isArray ( uploadOptions . extensions ) ) {
53+ formData . append ( 'extensions' , JSON . stringify ( uploadOptions . extensions ) ) ;
54+ } else if ( key === "customMetadata" && typeof uploadOptions . customMetadata === "object" &&
55+ ! Array . isArray ( uploadOptions . customMetadata ) && uploadOptions . customMetadata !== null ) {
56+ formData . append ( 'customMetadata' , JSON . stringify ( uploadOptions . customMetadata ) ) ;
5557 }
5658 else {
57- formData . append ( i , param ) ;
59+ formData . append ( key , String ( uploadOptions [ key ] ) ) ;
5860 }
5961 }
6062 }
0 commit comments