【发布时间】:2019-05-26 04:02:28
【问题描述】:
我正在尝试返回请求的图像文件。我的客户正在下载该文件,但我无法显示它,因为它是无效的png 文件。如果我打开存储的文件tmpFile.png,我可以正确看到它。所以问题可能在于我如何将它发送回请求它的客户。
// This is my controller
async getFile(@Param('bucketname') bucketName: string,
@Param('filename') fileName: string) {
return await this.appService.getFile(bucketName, fileName);
// This is the function called
getFile(bucketName: string, fileName: string) {
return new Promise(resolve => {
this.minioClient.getObject(bucketName, fileName, (e, dataStream) => {
if (e) {
console.log(e);
}
let size = 0;
const binary = fs.createWriteStream('tmpFile.png');
dataStream.on('data', chunk => {
size += chunk.length;
binary.write(chunk);
});
dataStream.on('end', () => {
binary.end();
resolve(binary);
});
});
});
}
【问题讨论】:
-
标题具有误导性。它应该被指定为“[AWS]使用nestjs正确返回图像文件”
-
为什么应该是aws?
标签: javascript rest nestjs