简介
文件下载非常简单,仅需通过res.download()执行即可,他可以写为3种形式:
res.download('/report-12345.pdf');
res.download('/report-12345.pdf', 'report.pdf');
res.download('/report-12345.pdf', 'report.pdf', function(err){
if (err) {
// 错误处理,注意他可能会部分发送响应
// 因此请检查好 res.headersSent
} else {
// 减少下载验证
}
});
以下是一个对选择对应文件进行下载的实例:
html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body