Skip to content

Instantly share code, notes, and snippets.

@Alexisgt01
Created March 2, 2020 06:59
Show Gist options
  • Save Alexisgt01/8aaf93ff2d318055ba071b135913e1e8 to your computer and use it in GitHub Desktop.
Save Alexisgt01/8aaf93ff2d318055ba071b135913e1e8 to your computer and use it in GitHub Desktop.
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