Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
web-et-numerique
web-et-numerique-internet
data.grandlyon.com
web-portal
components
custom-apps
web-app
Commits
8e590100
Commit
8e590100
authored
Apr 08, 2022
by
Matthieu BENOIST
Browse files
Merge branch 'DOS0186370' into 'master'
Corrects some pdf download problems with neogeo services See merge request
!162
parents
935ecf03
aba2b1ea
Pipeline
#25006
passed with stage
in 10 minutes and 15 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/app/shared/components/download-button/download-button.component.ts
View file @
8e590100
import
{
HttpClient
,
HttpResponse
}
from
'
@angular/common/http
'
;
import
{
toBase64String
}
from
'
@angular/compiler/src/output/source_map
'
;
import
{
Component
,
Input
,
OnDestroy
,
OnInit
,
OnChanges
}
from
'
@angular/core
'
;
import
{
Subject
}
from
'
rxjs
'
;
import
{
takeUntil
}
from
'
rxjs/operators
'
;
...
...
@@ -40,16 +41,49 @@ export class DownloadButtonComponent implements OnInit, OnDestroy, OnChanges {
takeUntil
(
this
.
ngUnsubscribe
),
).
subscribe
(
(
response
)
=>
{
// Create a temporary link and click on it to launch the blob download
const
url
=
window
.
URL
.
createObjectURL
(
response
.
body
);
const
a
=
document
.
createElement
(
'
a
'
);
a
.
href
=
url
;
a
.
rel
=
'
noopener
'
;
a
.
download
=
this
.
fileName
;
document
.
body
.
appendChild
(
a
);
// append the element to the dom -> otherwise it will not work in firefox
a
.
click
();
a
.
remove
();
this
.
loading
=
false
;
if
(
response
.
body
.
type
==
'
application/pdf
'
)
{
var
reader
=
new
FileReader
();
reader
.
readAsDataURL
(
response
.
body
);
reader
.
onloadend
=
()
=>
{
const
bytes
=
reader
.
result
.
toString
();
//what we realy have ?
const
header
=
bytes
.
substring
(
0
,
bytes
.
indexOf
(
'
,
'
)
+
1
);
var
str
=
bytes
.
substring
(
bytes
.
indexOf
(
'
,
'
)
+
1
);
const
b64
=
atob
(
str
).
replace
(
'
"
'
,
''
);
var
newData
=
''
;
try
{
atob
(
b64
.
replace
(
'
"
'
,
''
));
newData
=
header
+
b64
.
replace
(
'
"
'
,
''
);
}
catch
(
e
)
{
newData
=
bytes
;
}
finally
{
const
a
=
document
.
createElement
(
'
a
'
);
a
.
href
=
newData
;
a
.
rel
=
'
noopener
'
;
a
.
download
=
this
.
fileName
;
document
.
body
.
appendChild
(
a
);
// append the element to the dom -> otherwise it will not work in firefox
a
.
click
();
a
.
remove
();
this
.
loading
=
false
;
}
}
}
else
{
const
a
=
document
.
createElement
(
'
a
'
);
a
.
href
=
url
;
a
.
rel
=
'
noopener
'
;
a
.
download
=
this
.
fileName
;
document
.
body
.
appendChild
(
a
);
// append the element to the dom -> otherwise it will not work in firefox
a
.
click
();
a
.
remove
();
this
.
loading
=
false
;
}
},
(
err
)
=>
{
let
message
=
notificationMessages
.
general
.
failedDownloadFile
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment