async download() {
const filePath = path.resolve(this.app.config.static.dir, 'hello.txt');
this.ctx.attachment('hello.txt');
this.ctx.set('Content-Type', 'application/octet-stream');
this.ctx.body = fs.createReadStream(filePath);
}
async downloadImage() {
const url = 'http://cdn2.ettoday.net/images/1200/1200526.jpg';
const res = await this.ctx.curl(url, {
streaming: true,
});
this.ctx.type = 'jpg';
this.ctx.body = res.res;
}
}
egg下载
最新推荐文章于 2022-03-09 11:32:00 发布