0

Here's what i've done so far. I managed to download the file but it's giving me "object%200%object" on the url when i try to open the file.

     fetch({
        url,
        method: 'GET',
        responseType: 'blob', // important
        contentDisposition: 'attachment',
        contentType: 'application/pdf',
        mode: 'no-cors'
    })
    .then(r => r.blob())
    .then((response) => {
        console.log(response);
        const s = window.URL.createObjectURL(new Blob([response.data]));
        const link = document.createElement('a');

        link.setAttribute('download', `test.pdf`);
        link.click();
    });
  • 1
    Possible duplicate of https://stackoverflow.com/questions/6794255/html-download-a-pdf-file-instead-of-opening-them-in-browser-when-clicked? – Ramya Oct 03 '18 at 11:36
  • @RamyaRamanathan Thanks for the response mate! Though it's keeps opening a new tab here's my code: `let path= "http://example.pdf";` `let save = document.createElement('a');` `save.href = path;` `save.download = 'test';` `save.target = '_blank';` `document.body.appendChild(save);` `save.click();` `document.body.removeChild(save);` – Nil Jimenez Jr. Oct 03 '18 at 11:49

0 Answers0