Configuration of Response Headers

2

I created a server in Express and my client in Quasar / VueJS. I need to send a PDF to my client, the PDF in question is already created on the server, but I'm having trouble sending it to the client. I'm using Axios to make client-side requests. Here is the code below:

Client:

axios({
      url: '/server/gerarpdf',
      method: 'post',
      data: this.pessoas,
      type: 'application/json',
      responseType: 'application/pdf'})
    .then(function (response) {
      let file = new Blob([response.data], {type: 'application/pdf'})
      let fileURL = URL.createObjectURL(file)
      window.open(fileURL)
    })
    .catch(function (error) {
      console.log(error)
    })

Server:

res.setHeader('content-type', 'application/pdf');
    res.setHeader('content-disposition', 'attachment; filename=Tabela.pdf');
    let filePath = "C:/Projetos/Relatorios/pdfs/Tabela.pdf";
    let fileName = 'PDF.pdf'; //
    res.download(filePath, fileName, function (err, results) {
        if(err){
            console.log(err)
        }else {
            console.log('Baixou!!')
        }
    });

Before the PDF did not open, it now opens but goes blank, and when I open it manually all the content of it appears normally. My question is: Which headers should I configure on both the server and the client? How do I do that when it opens I do not get the Blob address I'm using, type this: "bb560c1c-5d9e-429a-8330-80e2e55e0a42" ??

Thank you in advance

    
asked by anonymous 15.08.2017 / 15:05

0 answers