title: NodeJS How do I Download a file to disk from an aws s3 bucket?
body: <p>My goal:</p>
  
  <p>Display a dialog box prompting the user to save a file being downloaded from aws.</p>
  
  <p>My problem:</p>
  
  <p>I am currently using awssum-amazon-s3 to create a download stream. However I've only managed to save the file to my server or stream it to the command line... As you can see from my code my last attempt was to try and manually set the content disposition headers which failed. I cannot use res.download() as the headers have already been set?</p>
  
  <p>How can I achieve my goal?</p>
  
  <p>My code for node:</p>
  
  <pre><code>app.post('/dls/:dlKey', function(req, res, next){
          // download the file via aws s3 here
          var dlKey = req.param('dlKey');
  
          Dl.findOne({key:dlKey}, function(err, dl){
              if (err) return next(err);
              var files = dl.dlFile;
  
              var options = {
                  BucketName    : 'xxxx',
                  ObjectName    : files,
              };
  
              s3.GetObject(options, { stream : true }, function(err, data) {
                  // stream this file to stdout
                  fmt.sep();
                  data.Headers['Content-Disposition'] = 'attachment';
                  console.log(data.Headers);
                  data.Stream.pipe(fs.createWriteStream('test.pdf'));
                  data.Stream.on('end', function() {
                      console.log('File Downloaded!');
                  });
              });
          });
  
          res.end('Successful Download Post!');
      });
  </code></pre>
  
  <p>My code for angular:</p>
  
  <pre><code>$scope.dlComplete = function (dl) {
          $scope.procDownload = true;
          $http({
              method: 'POST',
              url: '/dls/' + dl.dlKey
          }).success(function(data/*, status, headers, config*/) {
              console.log(data);
              $location.path('/#!/success');
          }).error(function(/*data, status, headers, config*/) {
              console.log('File download failed!');
          });
      };
  </code></pre>
  
  <p>The purpose of this code it to let users use a generated key to download a file once.</p>