nodejs 下载文件时缺少后缀名

exports.download = async (ctx, next) => {
  const caseId = ctx.params._id
  const downloadPath = path.join('temp', 'md', `${caseId}.md`)

  const file = await fs.readFile(downloadPath)
  ctx.body = file
}

koa :根据 id 下载服务器上的文件,文件是 .md 文件。但请求该路由后下载的文件是无后缀名的,该如何让下载时保留后缀名?

阅读 3.9k
1 个回答

使用 koa 的 ctx.attachment() 方法即可。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题