【发布时间】:2016-12-15 14:48:36
【问题描述】:
在学习方面我需要自己用fs.streams制作文件上传
router.post('/upload', (req, res, next) => {
req.pipe(fs.createWritableStream('files/file.png'))
.on('error', (err) => next(err))
.on('close', () => {
res.json({image: 'files/file.png'});
})
})
这是行不通的。所以两个问题
- 如何从req中获取文件名和数据?
- 如何连接这两个流?
更新:在所有教程中描述了相反的操作 - 从 fs 和 pipe 读取文件到 res 到最终用户。
【问题讨论】:
-
你找到解决这个问题的方法了吗?