Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
web-app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
web-et-numerique-internet
data.grandlyon.com
web-portal
components
custom-apps
web-app
Commits
aba2b1ea
Commit
aba2b1ea
authored
3 years ago
by
Matthieu Benoist
Browse files
Options
Downloads
Patches
Plain Diff
corrects some pdf download problems with neogeo services
parent
935ecf03
No related branches found
No related tags found
1 merge request
!162
Corrects some pdf download problems with neogeo services
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/shared/components/download-button/download-button.component.ts
+43
-9
43 additions, 9 deletions
...d/components/download-button/download-button.component.ts
with
43 additions
and
9 deletions
src/app/shared/components/download-button/download-button.component.ts
+
43
−
9
View file @
aba2b1ea
import
{
HttpClient
,
HttpResponse
}
from
'
@angular/common/http
'
;
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
{
Component
,
Input
,
OnDestroy
,
OnInit
,
OnChanges
}
from
'
@angular/core
'
;
import
{
Subject
}
from
'
rxjs
'
;
import
{
Subject
}
from
'
rxjs
'
;
import
{
takeUntil
}
from
'
rxjs/operators
'
;
import
{
takeUntil
}
from
'
rxjs/operators
'
;
...
@@ -40,16 +41,49 @@ export class DownloadButtonComponent implements OnInit, OnDestroy, OnChanges {
...
@@ -40,16 +41,49 @@ export class DownloadButtonComponent implements OnInit, OnDestroy, OnChanges {
takeUntil
(
this
.
ngUnsubscribe
),
takeUntil
(
this
.
ngUnsubscribe
),
).
subscribe
(
).
subscribe
(
(
response
)
=>
{
(
response
)
=>
{
// Create a temporary link and click on it to launch the blob download
const
url
=
window
.
URL
.
createObjectURL
(
response
.
body
);
const
url
=
window
.
URL
.
createObjectURL
(
response
.
body
);
const
a
=
document
.
createElement
(
'
a
'
);
a
.
href
=
url
;
if
(
response
.
body
.
type
==
'
application/pdf
'
)
{
a
.
rel
=
'
noopener
'
;
var
reader
=
new
FileReader
();
a
.
download
=
this
.
fileName
;
reader
.
readAsDataURL
(
response
.
body
);
document
.
body
.
appendChild
(
a
);
// append the element to the dom -> otherwise it will not work in firefox
reader
.
onloadend
=
()
=>
{
a
.
click
();
const
bytes
=
reader
.
result
.
toString
();
a
.
remove
();
//what we realy have ?
this
.
loading
=
false
;
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
)
=>
{
(
err
)
=>
{
let
message
=
notificationMessages
.
general
.
failedDownloadFile
;
let
message
=
notificationMessages
.
general
.
failedDownloadFile
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment