node.js - Redirect after download file - Nodejs -
i'm trying redirect page after downloading file. code:
app.get('/log', function(req,res){ return res.download('file.txt', function(err){ if(!err){ return res.render('index.html'); } }); })
but every time error: error: can't set headers after sent.
there way redirect/render after downloading? (at server-side, please).
you can't in way think headers sent download response.
you can accomplish manipulating response send required headers file download , send location header along with. requester should understand location header , redirect accordingly.
for eg.
const filedata = /* read file */; res.set({ 'content-type': 'text/plain', 'location': '/' }); res.end(filedata);
Comments
Post a Comment