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

4 comments:

  1. Getting Error

    The specified key does not exist
    even i have file.

    ReplyDelete
  2. That is really nice to hear. thank you for the update and good luck. main Image

    ReplyDelete
  3. Note that a file transfer administration saves your information in its web worker for a pre-chosen timeframe. file transfer

    ReplyDelete
  4. It throws an error.
    InvalidRequest
    The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-

    ReplyDelete

Powered by Blogger.