Skip to content
Snippets Groups Projects
utils.js 570 B
Newer Older
export function downloadFile(file) {
  const fileName =
    file.name && file.name.split('/').length && file.name.split('/').slice(-1)[0].split('.').length ?
      file.name.split('/').slice(-1)[0].split('.')[0] :
      'file';
  const href = URL.createObjectURL(file.url);
  const link = document.createElement('a');
  link.href = href;
  link.setAttribute('download', `${fileName}.${file.url.type === 'application/x-zip-compressed' ? 'zip' : 'pdf'}`);
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
  URL.revokeObjectURL(href);
}