Fetch: Provide example for File Download

Created on 27 Oct 2014  路  3Comments  路  Source: github/fetch

I tried to point someone to this repo who was asking a question about an easier replacement for XHR+FileSystem for File Downloads, but there seems not be an example for this use case specifically.

help wanted

Most helpful comment

+1

All 3 comments

I don't have a download example readily available that we can use here, but I would merge a pull request if someone else has an example.

+1

voil脿!!!

    fetch(url_to_file, {
      method : 'GET'
    })
      .then(result => result.blob())
      .then(result => {
          var a = document.createElement("a");
          document.body.appendChild(a);
          a.style = "display: none";
          var blob = new Blob([result], {type: "application/pdf"});
          var url = window.URL.createObjectURL(blob);
          a.href = url;
          a.download = "filename_here.pdf";
          a.click();
          window.URL.revokeObjectURL(url);
        }
      )
Was this page helpful?
0 / 5 - 0 ratings

Related issues

fczuardi picture fczuardi  路  3Comments

DimitryDushkin picture DimitryDushkin  路  4Comments

poppinlp picture poppinlp  路  4Comments

ccorcos picture ccorcos  路  3Comments

kocur4d picture kocur4d  路  3Comments