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.