Amazon S3

Download from Amazon S3 using JavaScript and Visualforce

Download from Amazon S3 using Javascript

In continuation to the post where I explained how to upload to Amazon S3 using Javascript  , this post will focus on downloading the document from Amazon S3 using native JavaScript and Visualforce page.

Copy and paste the below JavaScript code in the VF page which would enable you to download the specified file. Change the text mentioned in Red

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1.12.min.js"></script>

    <script type="text/javascript">

         AWS.config.update(
      {
        accessKeyId: "YOUR AWS ACCESS KEY ID",
        secretAccessKey: "YOUR AWS SECRET ACCESS KEY",
        region_config: "eu-west-1" 
      }
     );
var s23 = new AWS.S3();
var y="Name of the file which is to be downloaded";

var params = {Bucket: 'BUCKET NAME', Key: y};
s23.getSignedUrl('getObject', params, function (err, url) {
    window.open(url,"_self");
});
</script>

If you have any question don't hesitate to mention them in comments!!

About Saurabh Dua

1 comments:

  1. Getting Error

    The specified key does not exist
    even i have file.

    ReplyDelete

Powered by Blogger.