c# - How can I non-recursively browse the contents of a directory with the AWS S3 API? -



c# - How can I non-recursively browse the contents of a directory with the AWS S3 API? -

say have next directories , files in amazon s3 bucket (files in bold):

bucketname/ bucketname/folder1/ bucketname/folder1/foobar.txt bucketname/folder1/subfolder1/ bucketname/folder1/subfolder1/hello.txt bucketname/folder1/subfolder2/ bucketname/folder1/subfolder2/world.txt bucketname/folder1/subfolder2/subsubfolder1/ bucketname/folder1/subfolder2/subsubfolder1/file.txt

how can list objects , immediate subdirectories of given directory .net aws s3 api, without recursively getting below directory? in other words, how can "browse" contents of directory @ single level?

for example, imagine want browse contents of bucketname/folder1/. see following:

bucketname/folder1/foobar.txt bucketname/folder1/subfolder1/ bucketname/folder1/subfolder2/

...and nil else. don't want list files , directories in subdirectories, want list files , subdirectories @ folder1 level.

is there way apply filters single aws api phone call doesn't homecoming everything , forcefulness me manually parse need?

i've found code let's me immediate subdirectories (as intended), can't figure out how include immediate files too:

var request = new listobjectsrequest() .withbucketname("bucketname") .withprefix(@"folder1/") .withdelimiter(@"/"); using (var client = amazon.awsclientfactory.createamazons3client(accesskey, secretkey)) using (var response = client.listobjects(request)) { foreach (var item in response.commonprefixes) { /* ... */ } }

i had opposite problem (i knew how files in specified folder, not subdirectories).

the reply amazon lists files differently sub-folders.

sub-folders listed, illustration shows, in listobjectsresponse.commonprefixes collection.

files listed in listobjectsresponse.s3objects collection.

so code should this:

var request = new listobjectsrequest() .withbucketname("bucketname") .withprefix(@"folder1/") .withdelimiter(@"/"); using (var client = amazon.awsclientfactory.createamazons3client(accesskey, secretkey)) using (var response = client.listobjects(request)) { foreach (var subfolder in response.commonprefixes) { /* list sub-folders */ } foreach (var file in response.s3objects) { /* list files */ } }

my google search turned post on burningmonk blog in comment section:

when create lis­to­b­jects request, list top level fold­ers, don’t set pre­fix set delim­iter ‘/’, inspect ‘com­mon­pre­fixes’ prop­erty on response fold­ers in top folder.

to list con­tents of ‘root­folder’, create request pre­fix set name of folder plus back­slash, e.g. ‘rootfolder/’ , set delim­iter ‘/’. in response you’ll have folder ele­ment same key pre­fix used in request, plus sub­fold­ers in ‘com­mon­pre­fixes’ property.

c# .net amazon-s3

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -