因此,我已经成功地使用Multer和Multer-Gridfs-Storage将我的图像文件下载到了我的MongoDB上,但我在检索它时遇到了麻烦。
当我尝试使用GridFS-Stream检索数据时,返回的结果类似于前面的问题:GridFS : How to display the result of readstream.pipe(res) in an tag?
当我使用这段代码时,发送到我的前端的只是集合中的第一个块,但它实际上是可用的。
const readstream = gfs.createReadStream({ filename: files[0].filename });
readstream.on('data', (chunk) => {
res.send({ image: chunk.toString('base64') })
})我怎样才能取回所有的块呢?我应该放弃并开始使用GridFSBucket吗?
发布于 2019-10-05 11:51:27
我最终尝试了一下,并且成功了!
let data = ''
readstream.on('data', (chunk) => {
data += chunk.toString('base64')
})
readstream.on('end', () => {
res.send(data)
})https://stackoverflow.com/questions/58245166
复制相似问题