GET files from s3 to local

Hi
Recently I started working on an app based on Meteor platform.i want to upload and also GET files from amazon s3 from my meteor app .
i have the s3.config details.
Iam able to successfully upload files to s3 .
But how to ‘‘GET’’ files from s3 to local?

thanks in advance…

Depends what you want to do, assuming you have private files on S3 you can use the aws-sdk npm package. Then you can request a signed url which will display your object (image, pdf, video etc.)

const AWS = require('aws-sdk');
const s3 = new AWS.S3();

const params = {
  Bucket: 'MY_BUCKET',
  Key: 'path/to/file.fileExtension'
}
const url = s3.getSignedUrl('getObject', params);

If you do not care about that privacy factor, which there are cases where it really doesnt matter, then you can make your file public in s3 and just include it as a link.

Hope that helps!

1 Like

Instead of making your file public you might add a new Bucket Privacy Policy where you add any http referrer you wish that will be authorized to download files from the bucket.

It’d look something like this:


	"Version": "2008-10-17",
	"Id": "Policy1414368633278",
	"Statement": [
		{
			"Sid": "Stmt1414368595009",
			"Effect": "Allow",
			"Principal": {
				"AWS": "*"
			},
			"Action": "s3:GetObject",
			"Resource": "arn:aws:s3:::YOURBUCKETNAME/*",
			"Condition": {
				"StringLike": {
					"aws:Referer": "http://YOURDOMAINNAME.com/*"
				}
			}
		}
	]
}

“aws:Referer” also accepts an array of strings so you might add multiple domains, including localhost so you can test locally.

Here there is a good step by step guide that explains in detail what you would need to do:

The above however downloads the object to the user’s browser, and not to the server neither stores anything there.

2 Likes

can we create a new bucket in AWS S3 from our local meteor app ??

i have tried using s3.createBucket method but i was getting

error:
TypeError: stream.setTimeout is not a function

thankyou

Once we get Signed url, how to download the contents of S3 file?