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,090 points
13,351 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!

Hope this helps!!

To know more about Java, join our Java course online today.

Thank you

answered Dec 31, 2018 by Archana
• 5,640 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 8, 2020 in AWS by MD
• 95,460 points
8,252 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
• 58,020 points
2,100 views
0 votes
1 answer
+1 vote
2 answers

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,640 points
54,420 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP