Javascript code to download a file from Amazon S3

0 votes

Is there a javascript code to download a file from Amazon S3? I couldn't find anything useful resources on the internet. So, if any of you have done something similar to this can you post the code?  Well, is it possible to write a javascript code to download a file from S3?

Dec 31, 2018 in AWS by datageek
• 3,050 points
6,925 views

1 answer to this question.

0 votes

Hai, I was thinking along the same lines. Then I figured out I could make use of node.js, ie. use AWS SDK for javascript in node.js.

var AWS = require('aws-sdk');
AWS.config.update(
  {
    accessKeyId: ".. your key ..",
    secretAccessKey: ".. your secret key ..",
  }
);
var s3 = new AWS.S3();
s3.getObject(
  { Bucket: "my-bucket", Key: "my-picture.jpg" },
  function (error, data) {
    if (error != null) {
      alert("Failed to retrieve an object: " + error);
    } else {
      alert("Loaded " + data.ContentLength + " bytes");
    }
  }
);
Try this out!
answered Dec 31, 2018 by Archana
• 5,600 points
How to display or the download the file to client side. can you add the code for that also

Hi Prashanth,

To run your script on the client-side, you need to use some automation tools. Generally in this type of use case, we use Terraform. But we can also use the Ansible playbook to do this task.

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer

How to download a file from S3 buckets using boto3?

Hi@akhtar, Boto3 supports upload_file() and download_file() APIs to ...READ MORE

answered Oct 7 in AWS by MD
• 65,800 points
70 views
0 votes
1 answer

How to copy .csv file from Amazon S3 bucket?

Boto3 is the library to use for ...READ MORE

answered Jul 6, 2018 in AWS by Priyaj
• 57,700 points
901 views
0 votes
1 answer
–1 vote
1 answer

How to read a csv file stored in Amazon S3 using csv.DictReader

The code would be something like this: import ...READ MORE

answered Oct 25, 2018 in AWS by Archana
• 5,600 points
29,751 views