Reputation: 1489
Is there a way to get a file list from a bucket in amazon s3?
I'm using Lepozepo/S3 Package
I see this SO, which recommends using boto, but I'm wondering if there is another way to get the files.
Upvotes: 0
Views: 999
Reputation: 176
Here is how I do it:
Use the very popular AWS SDK package: https://atmospherejs.com/peerlibrary/aws-sdk
Then the code snippet (on server) will look like:
AWS.config.update({
accessKeyId: '<accessKey>',
secretAccessKey: '<secretKey>'
});
s3 = new AWS.S3({
region: 'us-west-2'
});
var params = {
Bucket: 'bucketName'
};
s3.listObjects(params, Meteor.bindEnvironment(function (err, data) {
//DO STUFF HERE
}));
Hope that's useful, if you have any problems, just shout!
Upvotes: 1
Reputation: 1327
one of the way you can get the list of files from a bucket in Amazon S3 is using aws-sdk for java. below is an example of that. To get the credetials passing there are advanced methods now, which shown below is not secure.
AWSCredentials credentials = new BasicAWSCredentials(accessKeyId,secretAccessKey);
AmazonS3 s3Client = new AmazonS3Client(credentials);
String bucket = prop.getProperty("bucket");
String directory = prop.getProperty("directory");
ListObjectsRequest lor = new ListObjectsRequest().withBucketName(bucket).withPrefix(directory);
ObjectListing objects = s3Client.listObjects(lor);
Then use the S3ObjectSummary class to iterate the objects and list the files.
Hope it helps!
Upvotes: 0