title: How to download large file using meteorjs, AWS s3 and Angularjs?
body: <p>Im pretty new to AWS and MeteorJ and I'm having issue downloading large files (100mb+). I would like the user to click the download button and the file start downloading right away. I might be wrong but the code looks like is downloading the file into memory and then sending it to the client-side.</p>
  
  <p>EDIT: The question is a bit different. I'm not calling the server function via http. I added the call to the server.</p>
  
  <p>Here is the call to the server: </p>
  
  <pre><code>function getFile(data) {
      const def = $q.defer();
  
      Meteor.call('downloadFileFromS3', data, (err, res) =&gt; {
          if (err) {
              return def.reject(err)
          }
  
          return def.resolve(res)
      });
  
      return def.promise;
  };
  </code></pre>
  
  <p>Here is the meteorjs code:</p>
  
  <pre><code>async downloadFileFromS3(params) {
      try {
          const criteria = {
              Bucket: params.bucket,
              Key: `${params.key}/${params.filename}`
          };
  
          const data = await s3.getObject(criteria).promise();
  
          return {
              data: data.Body,
              contentType: data.ContentType,
              filename: params.filename
          };
      } catch (ex) {
          throw new Meteor.Error('500', ex.message);
      }
  }
  </code></pre>
  
  <p>Here is what I'm doing in the client side:</p>
  
  <pre><code>function _download (data, filename) {
      const blob = new Blob([data.data], {type: data.contentType});
  
      const url = window.URL.createObjectURL(data);
      const el = document.createElement('a');
  
      el.style = 'display: none';
      el.href = url;
      el.download = filename;
  
      document.body.appendChild(el);
  
      el.click();
  
      window.URL.revokeObjectURL(url);
  }
  </code></pre>