Skip to content

Commit

Permalink
Use anchor element to trigger download
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasHirt committed Jul 21, 2020
1 parent 56e4184 commit f284c43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/plugins/phoenix.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ export default {
headers: { Authorization: 'Bearer ' + this.getToken }
}).then(res => {
if (res.status === 200) {
window.location = signedUrl
const a = document.createElement('a')
a.style.display = 'none'
document.body.appendChild(a)

a.href = signedUrl

console.log(file)
// Use download attribute to set desired file name
a.setAttribute('download', file.name)

// Trigger the download by simulating click
a.click()

// Cleanup
document.body.removeChild(a)
} else if (res.status === 404) {
this.showMessage({
title: this.$gettext('Download failed'),
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2917,9 +2917,9 @@ data-uri-to-buffer@1:
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-1.2.0.tgz#77163ea9c20d8641b4707e8f18abdf9a78f34835"
integrity sha512-vKQ9DTQPN1FLYiiEEOQ6IBGFqvjCa5rSK3cWMy/Nespm5d/x3dGFT9UBZnkLxCwua/IXBi2TYnwTEpsOvhC4UQ==

"davclient.js@git+https://github.com/owncloud/davclient.js.git":
"davclient.js@https://github.com/owncloud/davclient.js.git":
version "0.2.1"
resolved "git+https://github.com/owncloud/davclient.js.git#bf19f590451b3c0658913568053ec7f300f7dfc1"
resolved "https://github.com/owncloud/davclient.js.git#bf19f590451b3c0658913568053ec7f300f7dfc1"

de-indent@^1.0.2:
version "1.0.2"
Expand Down

0 comments on commit f284c43

Please sign in to comment.