File tree Expand file tree Collapse file tree 2 files changed +21
-12
lines changed
Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Original file line number Diff line number Diff line change @@ -314,16 +314,18 @@ export async function downloadObjectsAsZip({
314314 objectIds,
315315} : {
316316 objectIds : string [ ] ;
317- } ) : Promise < string > {
317+ } ) : Promise < { href : string ; disposition : string } > {
318318 const res = await axiosClient . post ( '/object/downloadZip' , {
319319 ObjectIds : objectIds ,
320320 } , {
321321 responseType : 'blob' ,
322322 } ) ;
323323
324- const data = URL . createObjectURL ( res . data ) ;
325- return data ;
326- } ;
324+ const href = URL . createObjectURL ( res . data ) ;
325+ const disposition = res . headers [ 'content-disposition' ] ;
326+
327+ return { href, disposition } ;
328+ }
327329
328330export const fetchTrashedIds = async ( {
329331 pageParam,
@@ -346,7 +348,7 @@ export async function trashRestoreObjects({
346348 } ) ;
347349
348350 return response . data ;
349- } ;
351+ }
350352
351353export async function trashDeletePermamnentObjects ( {
352354 objectIds,
@@ -358,10 +360,10 @@ export async function trashDeletePermamnentObjects({
358360 } ) ;
359361
360362 return response . data ;
361- } ;
363+ }
362364
363365export async function emptyTrash ( ) : Promise < boolean > {
364366 const response = await axiosClient . delete ( 'emptytrash' ) ;
365367
366368 return response . data ;
367- } ;
369+ }
Original file line number Diff line number Diff line change @@ -138,15 +138,22 @@ export const ImageGallery: React.FC = () => {
138138 downloadObjectMutation . mutate (
139139 { objectIds : selectedImages } ,
140140 {
141- onSuccess : ( href ) => {
142- // create "a" HTML element with href to file & click
141+ onSuccess : ( { href, disposition } ) => {
142+ // Extract filename from Content-Disposition header
143+ let filename = 'files.zip' ;
144+ if ( disposition ) {
145+ const match = disposition . match (
146+ / f i l e n a m e [ ^ ; = \n ] * = ( ( [ ' " ] ) .* ?\2| [ ^ ; \n ] * ) /
147+ ) ;
148+ if ( match && match [ 1 ] )
149+ filename = match [ 1 ] . replace ( / [ ' " ] / g, '' ) ;
150+ }
151+
143152 const link = document . createElement ( 'a' ) ;
144153 link . href = href ;
145- link . setAttribute ( 'download' , 'files.zip' ) ; //or any other extension
154+ link . setAttribute ( 'download' , filename ) ;
146155 document . body . appendChild ( link ) ;
147156 link . click ( ) ;
148-
149- // clean up "a" element & remove ObjectURL
150157 document . body . removeChild ( link ) ;
151158 URL . revokeObjectURL ( href ) ;
152159 } ,
You can’t perform that action at this time.
0 commit comments