title: NodeJS download file from AWS S3 Bucket
body: <p>I'm trying to make an endpoint in NodeJS/Express for downloading content from my AWS S3 Bucket.</p>
  
  <p>It works well, I can download the file in the client side but I can also see the stream preview in the Network tab which is annoying...</p>
  
  <blockquote>
    <p><strong>QUESTION</strong></p>
    
    <p>I'm wondering if what I'm doing is correct and a good practice. 
    Also would like to know if it's normal to see the output stream in the Network tab.</p>
    
    <p>How should I properly send I file from S3 to my client application using NodeJS/Express?</p>
  </blockquote>
  
  <p>I'm pretty sure other websites requests don't let you preview the content with a: "<em>Fail to load response data</em>".</p>
  
  <hr>
  
  <p>This is what I do in my NodeJS application to get the stream file from AWS S3:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>download(fileId) {
    const fileObjectStream = app.s3
      .getObject({
        Key: fileId
      })
      .createReadStream();
    this.res.set("Content-Type", "application/octet-stream");
    this.res.set(
      "Content-Disposition",
      'attachment; filename="' + fileId + '"'
    );
    fileObjectStream.pipe(this.res);
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>And in the client side I can see this:</p>
  
  <p><a href="https://i.stack.imgur.com/wXKo5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wXKo5.png" alt="enter image description here"></a></p>