title: How to return an image file correctly using nest.js?
body: <p>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 <code>png</code> file. If I open the stored file <code>tmpFile.png</code>, I can see it correctly. So probably the problem is on how I'm sending it back to the client asking for it.</p>
  
  <pre><code>// 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 =&gt; {
        this.minioClient.getObject(bucketName, fileName, (e, dataStream) =&gt; {
          if (e) {
            console.log(e);
          }
  
          let size = 0;
          const binary = fs.createWriteStream('tmpFile.png');
  
          dataStream.on('data', chunk =&gt; {
            size += chunk.length;
            binary.write(chunk);
          });
          dataStream.on('end', () =&gt; {
            binary.end();
            resolve(binary);
          });
        });
      });
    }
  </code></pre>