Rename PDf file before opening for preview

2

I'm getting a PDF file in response to a POST request, and on the server side I've set up the file name and everything else. But now I'm viewing it in the browser instead of downloading it and it no longer obeys the name placed on the server and is assigning another name, type this: "2050102b-7041-4cfa-9ebf-0c05af158005" and I'm not getting it receive a specific name In addition to the name being weird, the URL in the browser looks like this: "blob: link

Server:

stream.on('finish', function() {
    if (fs.existsSync('C:/Projetos/Relatorios/pdfs/Tabela.pdf')) {
        let options = {
            root: '../pdfs/',
            dotfiles: 'deny'
        };
        let fileName = 'Tabela.pdf';
        res.sendFile(fileName, options, function (err) {
            if (err){
                console.log(err)
            }else{
                console.log('Arquivo enviado!')
            }
        });
    }
})

Client:

let link = document.createElement('a')    
link.target = '_blank'
let url = window.URL.createObjectURL(blob);
link.href = url .split('/')[0] + '/' + url .split('/')[1].replace(/.*/, 'meuarquivo.pdf');

Server: Express 4.15.0

Client: VueJS / Quasar-Framework

    
asked by anonymous 16.08.2017 / 19:14

1 answer

0

Try setting the content response server's response header to PDF and the Content-disposition name to the file name. Before the res.sendFile line something like:

res.set({
    'Content-disposition', 'attachment; filename=${fileName}',
    'Content-type', 'application/pdf'
})
    
28.09.2017 / 19:05