Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 object listing

I am using aws-sdk using node.js. I want to list images in specified folder e.g.This is the directory that i want to fetch

I want to list all files and folder in this location but not folder (images) content. There is list Object function in aws-sdk but it is listing all the nested files also.

Here is the code :

var AWS = require('aws-sdk'); AWS.config.update({accessKeyId: 'mykey', secretAccessKey: 'mysecret', region: 'myregion'}); var s3 = new AWS.S3();  var params = {    Bucket: 'mystore.in',   Delimiter: '',   Prefix: 's/5469b2f5b4292d22522e84e0/ms.files'  }  s3.listObjects(params, function (err, data) {   if(err)throw err;   console.log(data); }); 
like image 906
Rohit Avatar asked Jun 09 '15 07:06

Rohit


People also ask

How do I view contents of S3 bucket?

To open the overview pane for an objectSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that contains the object. In the Objects list, choose the name of the object for which you want an overview.

Where are objects in Amazon S3 stored?

All objects are stored in S3 buckets and can be organized with shared names called prefixes. You can also append up to 10 key-value pairs called S3 object tags to each object, which can be created, updated, and deleted throughout an object's lifecycle.

Are S3 objects public by default?

By default, new S3 bucket settings do not allow public access, but customers can modify these settings to grant public access using policies or object-level permissions.


2 Answers

Folders are illusory, but S3 does provide a mechanism to emulate their existence.

If you set Delimiter to / then each tier of responses will also return a CommonPrefixes array of the next tier of "folders," which you'll append to the prefix from this request, to retrieve the next tier.

If your Prefix is a "folder," append a trailing slash. Otherwise, you'll make an unnecessary request, because the first request will return one common prefix. E.g., folder "foo" will return one common prefix "foo/".

like image 37
Michael - sqlbot Avatar answered Sep 22 '22 07:09

Michael - sqlbot


It's working fine now using this code :

var AWS = require('aws-sdk'); AWS.config.update({accessKeyId: 'mykey', secretAccessKey: 'mysecret', region: 'myregion'}); var s3 = new AWS.S3();  var params = {   Bucket: 'mystore.in',  Delimiter: '/',  Prefix: 's/5469b2f5b4292d22522e84e0/ms.files/' }  s3.listObjects(params, function (err, data) {  if(err)throw err;  console.log(data); }); 
like image 99
Rohit Avatar answered Sep 22 '22 07:09

Rohit