Created
March 2, 2020 06:59
-
-
Save Alexisgt01/8aaf93ff2d318055ba071b135913e1e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export function download(id) { | |
return api.get(`url/${id}`, { | |
responseType: 'blob', | |
}).then((responseBlob) => { | |
let mime = require('mime-types'); | |
let ext = mime.extension(responseBlob.headers['content-type']); | |
const url = window.URL.createObjectURL(new Blob([responseBlob.data])); | |
const link = document.createElement('a'); | |
link.href = url; | |
link.setAttribute('download', 'file.' + ext); | |
document.body.appendChild(link); | |
link.click(); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment