最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - How to implement downloading logic on strapi? - Stack Overflow

programmeradmin2浏览0评论

I am trying to implement downloading file on strapi controller. I tried this.

    const path = "/records/xxxx.mp4"
    if (!fs.existsSync(path)) {
      console.log("file does not exist", path);
      return ctx.throw(404, 'File not found');
    }
    // Set headers for the response
    ctx.set('Content-Type', 'application/octet-stream');
    ctx.set('Content-Disposition', `attachment; filename="conference.mp4"`);

    // Stream the file to the response
    const readStream = fs.createReadStream(path);
    return readStream.pipe(ctx.res);

But I got this error:

Error [ERR_STREAM_CANNOT_PIPE]: Cannot pipe, not readable

Who can help me? Thank you.

发布评论

评论列表(0)

  1. 暂无评论