gpt4 book ai didi

nestjs - 通过 Nestjs 从 url 下载图像

转载 作者:行者123 更新时间:2023-12-02 08:01:00 25 4
gpt4 key购买 nike

我想从 telegram 帐户下载用户个人资料图片,并使用 Nestjs 框架将其存储在本地存储中。

最佳答案

@Controller()
export class Controller {
constructor(
private readonly httpService: HttpService,
) {
}

@Get()
async downloadImage(@Res() res) {
const writer = fs.createWriteStream('./image.png');

const response = await this.httpService.axiosRef({
url: 'https://example.com/image.png',
method: 'GET',
responseType: 'stream',
});

response.data.pipe(writer);

return new Promise((resolve, reject) => {
writer.on('finish', resolve);
writer.on('error', reject);
});
}
}

关于nestjs - 通过 Nestjs 从 url 下载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56286086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com