Created
January 21, 2018 16:23
-
-
Save urbontaitis/427cf6445016f728871d0595f2e96a2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handleDownload = (e) => { | |
e.preventDefault() | |
axios({ | |
method: 'get', | |
url: 'http://test.net/backend/api/orders/20170601_53/items/51/attachments/26', | |
responseType: 'arraybuffer' | |
}).then( (response) => { | |
var blob = new Blob([response.data], {type: response.headers['content-type']}); | |
if (typeof window.navigator.msSaveBlob !== 'undefined') { | |
window.navigator.msSaveBlob(blob, 'filename.png'); | |
} else { | |
var blobURL = window.URL.createObjectURL(blob); | |
var tempLink = document.createElement('a'); | |
tempLink.style.display = 'none'; | |
tempLink.href = blobURL; | |
tempLink.setAttribute('download', 'filename.png'); | |
tempLink.setAttribute('target', '_blank'); | |
document.body.appendChild(tempLink); | |
tempLink.click(); | |
document.body.removeChild(tempLink); | |
window.URL.revokeObjectURL(blobURL); | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment