【问题标题】:How to serve word , excel , ppt and pdf files from node.js server如何从 node.js 服务器提供 word、excel、ppt 和 pdf 文件
【发布时间】:2021-10-19 05:26:08
【问题描述】:

我已成功将文件从 mongoDB 上传到我的 node.js 服务器

屏幕截图如下:

click here to see Screen Short

但我不知道如何将这些文件从 node.js 服务器提供给客户端..

非常感谢进步

【问题讨论】:

  • 请将您的代码直接发布到问题中,无需添加将来可能会失效的额外网址。

标签: node.js mongodb file file-upload autodesk-viewer


【解决方案1】:

你可以这样使用:

使用此代码,当您单击指向/pdf 端点的链接时,客户端将下载具有所需名称的文件。

app.get('/pdf', (req, res) => {
  res.set('Content-disposition', 'attachment; filename=' + desiredName)
  res.type(yourDataType)
  res.status(200).send(Buffer.from(yourBufferFromFile, 'binary'))
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 2013-09-27
    • 2016-01-18
    • 1970-01-01
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多