Skip to content

Instantly share code, notes, and snippets.

@railsstudent
Created June 16, 2020 03:45
Show Gist options
  • Save railsstudent/f0431c9c9a0810a197aeb92cd93829e9 to your computer and use it in GitHub Desktop.
Save railsstudent/f0431c9c9a0810a197aeb92cd93829e9 to your computer and use it in GitHub Desktop.
use file-saver to open file
// private getFileNameFromContentDisposition(res: FileDownloadResponse<Blob>) {
// const { contentDisposition } = res;
// const matches = /filename=([^;]+)/gi.exec(contentDisposition);
// const tempFilename = ((matches && matches[1]) || 'untitled').trim();
// const filename = tempFilename.replace(/["]/g, '');
// return filename;
// }
// static openFile(response: FileDownloadResponse<Blob>) {
// if (response && response.body) {
// const { contentType } = response;
// const filename = FileDownloadHelper.getFileNameFromContentDisposition(response);
// saveAs(new Blob([response.body], { type: contentType }), filename);
// }
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment