19
rated 0 times
[
22]
[
3]
/ answers: 1 / hits: 18766
/ 6 Years ago, fri, december 28, 2018, 12:00:00
I'm trying to return the requested image file. My client is downloading the file, but I can't display it because it's an invalid png
file. If I open the stored file tmpFile.png
, I can see it correctly. So probably the problem is on how I'm sending it back to the client asking for it.
// 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);
});
});
});
}
More From » rest