File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed
src/Shared/Hooks/UseDownload Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { API_STATUS_CODES } from '@Common/Constants'
6
6
import { ServerErrors } from '@Common/ServerError'
7
7
import { getDownloadResponse } from './service'
8
8
import { HandleDownloadProps } from './types'
9
+ import { getDefaultFileName } from './utils'
9
10
10
11
const useDownload = ( ) => {
11
12
const [ isDownloading , setIsDownloading ] = useState < boolean > ( false )
@@ -46,15 +47,7 @@ const useDownload = () => {
46
47
const a = document . createElement ( 'a' )
47
48
a . href = blobUrl
48
49
49
- a . download =
50
- fileName ||
51
- response . headers // File name from response headers
52
- ?. get ( 'content-disposition' )
53
- ?. split ( ';' )
54
- ?. find ( ( n ) => n . includes ( 'filename=' ) )
55
- ?. replace ( 'filename=' , '' )
56
- . trim ( ) ||
57
- 'file.tgz'
50
+ a . download = fileName || getDefaultFileName ( response . headers ) || 'file.tgz'
58
51
59
52
// Append the link element to the DOM
60
53
document . body . appendChild ( a )
Original file line number Diff line number Diff line change
1
+ export const getDefaultFileName = ( headers : Headers ) =>
2
+ headers
3
+ ?. get ( 'content-disposition' )
4
+ ?. split ( ';' )
5
+ ?. find ( ( n ) => n . includes ( 'filename=' ) )
6
+ ?. replace ( 'filename=' , '' )
7
+ . trim ( )
You can’t perform that action at this time.
0 commit comments