视频流返回前端无法播放
- Dominant language
- TypeScript
- Stars
- 19k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
### Discussed in https://github.com/eggjs/egg/discussions/4767
Originally posted by **liyang9331** September 27, 2021
```js
ctx.set('content-type', 'video/mp4');//设置返回类型
let stream = fs.createReadStream('./assets/test.mp4');
if (stream) {//判断状态
stream.on('open', function () {
console.log('文件打开')
});
stream.on('end', function () {
console.log("读取完毕")
})
stream.on('data', function (data) {
// console.log("读取文件流")
ctx.body = data
})
stream.on('err', function () {
console.log("发生错误")
})
stream.on('close', function () {
console.log('关闭')
// ctx.end
});
}
```
Contributor guide
Assessment
This issue has not been assessed yet.