title: AWS S3 Javascript SDK - download file from private bucket with key and secret in browser
body: <p>I have csv file in S3 private bucket that I have created key to access. I am successfully using key and secret in Python to download the csv file to disk. </p>
  
  <p>Now I am trying the <a href="http://docs.amazonaws.cn/en_us/AWSJavaScriptSDK/guide/browser-examples.html" rel="nofollow">AWSJavaScriptSDK</a> to use JavaScript in the browser to retrieve the csv file.</p>
  
  <p>Note this is something I will use only on my computer so not concerned about having key and secret in page.</p>
  
  <p>I have setup CORS properly and am successfully able to get the file name using the script below. I have also tried a variation of this code that lists all files in bucket which also works. So I am authenticating and accessing the bucket properly.</p>
  
  <p>But I cannot find any non Node.js examples to retrieve the csv file and download it to disk using the AWSJavaScriptSDK for JavaScript in the browser.</p>
  
  <pre><code>&lt;div id="status"&gt;&lt;/div&gt;
  &lt;ul id="objects"&gt;&lt;/ul&gt;
  
  &lt;script src="https://sdk.amazonaws.com/js/aws-sdk-2.6.3.min.js"&gt;&lt;/script&gt;
  
   &lt;script type="text/javascript"&gt;
  
      AWS.config.accessKeyId = 'xxxxxxxxxxxxxxxxx';
      AWS.config.secretAccessKey = 'xxxxxxxxxxxxxxxxx';
      AWS.config.region = 'us-east-1';
  
      // create the AWS.Request object
      var bucket = new AWS.S3();
  
      bucket.getObject({
          Bucket: 'xxxxxxxxxxxxxxx', 
          Key: 'filename.csv'})
          .on('success', function(response) {               
              console.log("Key was", response.request.params.Key );
          }).send();    
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>My ultimate goal is to use the csv file in a D3.js and chart data. </p>
  
  <p>How do I get the csv onto disk or even better stream it into the browser?</p>