📜  将字符串下载为文件 express js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:00.858000             🧑  作者: Mango

代码示例1
app.get('/download', (request, response) => {
  const fileData = 'SGVsbG8sIFdvcmxkIQ=='
  const fileName = 'hello_world.txt'
  const fileType = 'text/plain'

  response.writeHead(200, {
    'Content-Disposition': `attachment; filename="${fileName}"`,
    'Content-Type': fileType,
  })

  const download = Buffer.from(fileData, 'base64')
  response.end(download)
})