NodeJS CSVはファイル名と内容の文字化けをエクスポートします.
980 ワード
//
var userAgent = (req.headers['user-agent']||'').toLowerCase();
res.set('Content-Type', 'application/octet-stream;charset=utf-8');
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 {
res.setHeader('Content-Disposition', 'attachment; filename=' + new Buffer(filename).toString('binary'));
}
// excel
var dataBuffer = Buffer.concat([new Buffer('\xEF\xBB\xBF', 'binary'), new Buffer(data)]);
res.send(dataBuffer);
原文の住所:http://imziv.com/blog/article/read.htm?id=55