Skip to content

Commit aaf8897

Browse files
committed
Fix download file
1 parent b6403b2 commit aaf8897

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

isimip_data/metadata/assets/js/api/DatasetApi.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,18 @@ class DatasetApi {
9292

9393
static downloadFile(file) {
9494
if (file.file_url) {
95-
const iframe = document.createElement('iframe')
96-
iframe.style.display = 'none'
97-
iframe.src = file.file_url
98-
iframe.onload = function() {
99-
this.parentNode.removeChild(this)
100-
}
101-
document.body.appendChild(iframe)
95+
fetch(file.file_url)
96+
.then(response => response.blob())
97+
.then(blob => {
98+
const url = URL.createObjectURL(blob)
99+
const a = document.createElement('a')
100+
a.href = url
101+
a.download = file.name
102+
document.body.appendChild(a)
103+
a.click()
104+
document.body.removeChild(a)
105+
URL.revokeObjectURL(url)
106+
})
102107
}
103108
}
104109
}

0 commit comments

Comments
 (0)