Skip to content Skip to sidebar Skip to footer

How To Pipe A Pdf Download Response From An Api (node/express) To A Client (react)?

In my specific setup, I have a backend server which generates a pdf, and then when a certain endpoint is visited, the pdf download is triggered. However, due to security rules, I c

Solution 1:

I finally got it to work, after reluctantly installing downloadjs Basically I changed my frontend code to look like this:

import axios from 'axios';
import download from 'download';
...
function getPDFDownload() {
    let opts = {
        url: `${middleman_root}/download`,
        method: "GET",
        responseType: 'blob'
    };
    return axios(opts)
        .then((result) => {
            download(result.data, "file.pdf", result.headers['content-type']);
        }).catch((error) => {
            console.log(error);
        })
}

Post a Comment for "How To Pipe A Pdf Download Response From An Api (node/express) To A Client (react)?"