|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
How to get Objects by specifying bucket path def s3files = s3.listObjects("trial")
works great and returns all the s3files within the trial bucket, I am able to use the same to retrieve the files by speficifying the bucket path e.g to get all the files in docs folder, which is inside the trial, can I use something like def s3files = s3.listObjects("trial//docs") pls help |
|
|
Re: How to get Objects by specifying bucket pathPlease see the documentation for the S3Service#listObjects method that accepts a prefix argument, this will allow you to limit the listed objects based on an object prefix string:
http://jets3t.s3.amazonaws.com/api/org/jets3t/service/S3Service.html#listObjects(org.jets3t.service.model.S3Bucket,%20java.lang.String,%20java.lang.String) There is also a basic example in the JetS3t code samples here: http://jets3t.s3.amazonaws.com/toolkit/code-samples.html#listing James On Wed, Jan 14, 2009 at 3:07 AM, MarkAtHarvest <mark@...> wrote:
|
|
|
Re: How to get Objects by specifying bucket pathHi James,
Went though documentation link you gave and came up with solution to list all the objects in particular subdirectory e.g to list all the files in /trial/docs folder, S3Bucket[] buckList = s3.listAllBuckets() buckList?.each{ log.debug("Bucket Name is $it.name") if(it.name=="trial") { log.debug("Foound $it.name") String prefix = "docs/"; String delimiter = "/"; // Refer to the S3 guide for more information on delimiters S3Object[] filteredObjects = s3.listObjects(it, prefix, delimiter); filteredObjects.each{ log.debug("File Name is $it.key ") def getUrl = S3Service.createSignedGetUrl(it.bucketName,it.key, awsCredentials, expiryDate, false) log.debug("GET URL IS $getUrl") } } Let me try the listObjectsChunked method, mentioned on your reply to Amy, thank you
|
|
|
Re: How to get Objects by specifying bucket pathDear James,
I tried the get Objects chunked method, I do get all the files, but my common prefixes has nothing in it following is my directory structure harvesttrial (has 14 files and 2 folders) harvesttrial\abc.pdf (it has 14 files in it) harvesttrial\.. harvesttrial\docs\emp\pay\pay1.pdf harvesttrial\docs\emp\admin I get total 16 S3 Objects back when queried on harvesttrial, but my common prefix length is 0, here is the sample code String prefix=null S3ObjectsChunk chunk = s3.listObjectsChunked("harvesttrial", prefix, null, Constants.DEFAULT_OBJECT_LIST_CHUNK_SIZE, null, true); S3Object[] s3files = chunk.getObjects(); log.debug("s3files returned $s3files.length files") String[] commonPrefixes = chunk.getCommonPrefixes(); log.debug("returned commonsPrefixes $commonPrefixes.length") commonPrefixes.each{ log.debug("Chunk Commmon Prefixes are $it ") } regards Mark
|
|
|
Re: How to get Objects by specifying bucket pathYou will only get common prefixes when you use a non-null delimiter string, and that delimiter string occurs before the end of the object key names.
So, to find the "subdirectory" paths under harvesttrial, you need to use prefix="harvesttrial" and delimiter="/". --- http://www.jamesmurty.com On Thu, Jan 15, 2009 at 10:21 PM, MarkAtHarvest <mark@...> wrote:
|
|
|
Re: How to get Objects by specifying bucket pathThank you James, everything works good as mentioned
S3ObjectsChunk chunk = s3.listObjectsChunked("harvesttrial",null, "/", 1000, null,true); String[] commonPrefixes = chunk.getCommonPrefixes(); commonPrefixes.each{ S3ObjectsChunk subchunk = s3.listObjectsChunked("harvesttrial",it, "/", 1000, null,true); S3Object[] s3files = chunk.getObjects(); log.debug("Files in $subFolderPrefix returned $s3files.length files") } One small question is, if the sub folder has again subfolders, I do get those folders as S3Objects and also get them in common prefixes. so e.g harvestrial/docs/emp1 harvestrial/docs/emp2 When I print the list of files, I get, File Name is docs/employees/emp2_$folder$ I can ignore these files, which have $folder$, but I thought we should not even get them in files, when we are getting them in commonPrefixes. Thanks again.
|
|
|
Re: How to get Objects by specifying bucket pathMy guess is that the "docs/employees/emp2_$folder$" objects you are seeing are indeed real objects, and were probably created by the tool you used to upload your files. They are most likely place-holder objects that your upload program uses to keep track of your directory structure.
If you look at your bucket using the JetS3t Cockpit tool, it will show you exactly what objects are present in your bucket. Looking through this listing will allow you to easily see whether or not your listing results are unusual. HTH, James On Sat, Jan 17, 2009 at 6:52 PM, MarkAtHarvest <mark@...> wrote:
|
|
|
Re: How to get Objects by specifying bucket pathI checked the cockpit tool, and it explains it all, the $folder$ is comingfrom my S3 Fox plugin for FireFox, which I was using to create directories. Jets3t kit is right in exposing it.
Thank you very much for all the help. ![]() ![]()
|
| Free embeddable forum powered by Nabble | Forum Help |