@@ -29,7 +29,7 @@ export default async (
2929 apiKey : string ,
3030 publicKey : string ,
3131 auth_token : string ,
32- uploadProgressCallback : ( data : IUploadProgressCallback ) => void
32+ uploadProgressCallback ? : ( data : IUploadProgressCallback ) => void
3333) : Promise < { data : IFileUploadedResponse [ ] } > => {
3434 try {
3535 let keyMap = { } as any
@@ -73,40 +73,42 @@ export default async (
7373 )
7474 } )
7575
76- const controller = new AbortController ( )
77- const signal = controller . signal
78- const response = await retryFetch ( endpoint , {
79- method : 'POST' ,
80- body : formData ,
81- timeout : 7200000 ,
82- headers : {
83- Encryption : `${ true } ` ,
84- Authorization : token ,
85- } ,
86- signal,
87- } )
76+ const response = uploadProgressCallback
77+ ? await retryFetch ( endpoint , {
78+ method : 'POST' ,
79+ body : formData ,
80+ timeout : 7200000 ,
81+ headers : {
82+ Encryption : `${ true } ` ,
83+ Authorization : token ,
84+ } ,
85+ onProgress : ( progress ) => {
86+ uploadProgressCallback ( {
87+ progress : progress ,
88+ } )
89+ } ,
90+ } )
91+ : await retryFetch ( endpoint , {
92+ method : 'POST' ,
93+ body : formData ,
94+ timeout : 7200000 ,
95+ headers : {
96+ Encryption : `${ true } ` ,
97+ Authorization : token ,
98+ } ,
99+ } )
88100 if ( ! response . ok ) {
89101 throw new Error ( `HTTP error! status: ${ response . status } ` )
90102 }
91103
92104 const reader = response . body ?. getReader ( )
93- const contentLength = + response . headers . get ( 'Content-Length' ) !
94- let receivedLength = 0
95105 let chunks = [ ]
96106 while ( true ) {
97107 const { done, value } = await reader ! . read ( )
98108 if ( done ) {
99109 break
100110 }
101111 chunks . push ( value )
102- receivedLength += value . length
103- uploadProgressCallback ( {
104- progress : contentLength
105- ? Math . round ( receivedLength / contentLength )
106- : 0 ,
107- total : contentLength || 0 ,
108- uploaded : receivedLength ,
109- } )
110112 }
111113
112114 let responseData = new TextDecoder ( 'utf-8' ) . decode (
0 commit comments