Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to download a file from amazon s3 bucket?

I was trying to download a file from a bucket on Amazon S3. I was wondering if I can write a javascript to download such a file from a bucket. I was googling it, but couldn't find any resources that can help me do that.

Some steps in mind are: authenticate Amazon S3, then by providing bucket name, and file(key), download or read the file so that I can be able to display the data in the file.

Thanks,

like image 752
c0mrade Avatar asked May 28 '13 19:05

c0mrade


People also ask

How do I download content from S3 bucket?

To download an entire bucket to your local file system, use the AWS CLI sync command, passing it the s3 bucket as a source and a directory on your file system as a destination, e.g. aws s3 sync s3://YOUR_BUCKET . . The sync command recursively copies the contents of the source to the destination.

How do I download a file using Javascript?

To ask the browser to download a file it can render, use the following header: Content-Disposition: attachment; filename="downloaded. pdf" (you can of course customize the filename as you need).

How do I download from Amazon S3 using Java?

To download the file we need a file name which is a key to represent file in the S3 bucket. To implement this we are using Spring boot with aws-java-sdk-s3. Amazon S3 Java SDK provides a simple interface that can be used to store and retrieve any amount of data, at any time, from anywhere on the web.

How do I download from Amazon S3 folder?

How to Download a Folder from AWS S3 # Use the s3 cp command with the --recursive parameter to download an S3 folder to your local file system. The s3 cp command takes the S3 source folder and the destination directory as inputs and downloads the folder.


1 Answers

Maybe you can use AWS Node.js API:

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");       // do something with data.Body     }   } ); 
like image 115
yegor256 Avatar answered Sep 20 '22 05:09

yegor256