【发布时间】:2022-01-23 03:20:20
【问题描述】:
我们先将要发布的文件发送如下:
router.post('/savefile', multer().single('filesource'), (q,s) => {
db.query("insert into filesource (filerefid, source) values ($1, $2) returning filerefid", [ q.body.filerefid, q.file ])
.then (r=> s.send(r.rows[0]))
})
然后尝试在 HTML 中显示如下:
<object type="application/pdf" data="http://localhost:3000/getsource/1"></object>
请求者:
router.get('/getsource/:i', (q,s) => {
db.query('select source from filesource where filerefid = $1;',
[q.params.i])
.then (r=> s.send(Buffer.from(r.rows[0].source.buffer)))
})
但是文件不能像那样正确显示或下载,最好的方法是什么,而不将文件保存在任何目录中?
【问题讨论】:
标签: node.js postgresql express multer node-postgres