報錯內容:
解決方案:
const filename = 'Nodejs中文指南.pdf';
const userAgent = (req.headers['user-agent'] || '').toLowerCase();
if (userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
res.setHeader('Content-Disposition', 'attachment; filename=' + encodeURIComponent(filename));
} else if (userAgent.indexOf('firefox') >= 0) {
res.setHeader('Content-Disposition', 'attachment; filename*="utf8\'\'' + encodeURIComponent(filename) + '"');
} else {
/* safari等其餘非主流瀏覽器只能自求多福了 */
res.setHeader('Content-Disposition', 'attachment; filename=' + new Buffer(filename).toString('binary'));
}