Skip to content

Instantly share code, notes, and snippets.

@Tomassito
Forked from javilobo8/download-file.js
Last active March 11, 2022 23:53
Show Gist options
  • Save Tomassito/a5b4d29f459b9383dc3daa313ae5f73b to your computer and use it in GitHub Desktop.
Save Tomassito/a5b4d29f459b9383dc3daa313ae5f73b to your computer and use it in GitHub Desktop.

Revisions

  1. Tomassito revised this gist May 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion download-file.js
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,6 @@ axios({
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', 'file.pdf');
    document.body.appendChild(link);
    link.click();
    window.URL.revokeObjectURL(url);
    });
  2. @javilobo8 javilobo8 revised this gist May 11, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion download-file.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ axios({
    method: 'GET',
    responseType: 'blob', // important
    }).then((response) => {
    const url = window.URL.createObjectURL(new Blob([data]));
    const url = window.URL.createObjectURL(new Blob([response.data]));
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', 'file.pdf');
  3. @javilobo8 javilobo8 created this gist May 11, 2017.
    12 changes: 12 additions & 0 deletions download-file.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    axios({
    url: 'http://localhost:5000/static/example.pdf',
    method: 'GET',
    responseType: 'blob', // important
    }).then((response) => {
    const url = window.URL.createObjectURL(new Blob([data]));
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', 'file.pdf');
    document.body.appendChild(link);
    link.click();
    });