跳到主要内容
CNode

koa关于createReadStream请求视频报错Error: write ECONNRESET

问答
KKrisBiuBiu发布于 8 年前
018500

在浏览器中直接请求,或者放在video标签中都是没有问题的。 但是在app中请求视频的话就会报错write ECONNRESET,因为对前端不熟,而且其他网站的视频在app上都可以播放。所以不敢把锅推给被人。 麻烦路过的大佬帮忙看一下,在Google上也找不到合理的解决办法,实在是束手无策了。

错误信息: Error: write ECONNRESET code:"ECONNRESET" errno:"ECONNRESET" headerSent:true message:"write ECONNRESET" stack:"Error: write ECONNRESET\n at _errnoException (util.js:1024:11)\n at WriteWrap.afterWrite [as oncomplete] (net.js:867:14)" syscall:"write" proto:Object {constructor: , name: "Error", message: "", …}

主要代码: const path = require('path'); const fss = require('fs'); const {filePath} = ctx; if(filePath && ctx.method === 'GET') { if(ctx.lastModified && ctx.fresh) { ctx.status = 304; return } let ext = path.extname(ctx.filePath); ext = ext.replace('.', ''); if(ext == "mp4"){ ctx.body = await fss.createReadStream(filePath); } await next();

查看回复

回复 (0)

暂无回复,成为第一个参与讨论的人。

参与回复

登录后即可参与回复。登录