On Tuesday 15 December 2009 02:11:22 pm Tomas Zulberti wrote:
> On Dec 14, 12:35 pm, Chris Moyer <
koper...@gmail.com> wrote:
> > S3 doesn't have a concept of "Folders" as you put it. It only has a
> > concept of being able to filter based on the name of the key. The only
> > real way to create a so-called "folder" is to actually make a key
> > under that path.
>
> I know that folders doesn't exits in S3. The question is who to check
> if the key exists because when I use
> - bucket.get_key('folder/')
> - bucket.get_key('folder')
>
Then you need to realize that there is no key "folder" or "folder/", unless
you created it specifically.
If you want to do what Firefox S3 organizer etc are doing, then you need to
look at the S3 docs on listing results. Specifically the prefix, and
delimiter arguments.
Pasted below from current svn trunk.
Specifically, use "list" with appropriate delimiters and prefixes, and see if
the result set is empty or not. If it is empty, then the "folder" does not
exists.
----
def list(self, prefix='', delimiter='', marker='', headers=None):
"""
List key objects within a bucket. This returns an instance of an
BucketListResultSet that automatically handles all of the result
paging, etc. from S3. You just need to keep iterating until
there are no more results.
Called with no arguments, this will return an iterator object across
all keys within the bucket.
:type prefix: string
:param prefix: allows you to limit the listing to a particular
prefix. For example, if you call the method with
prefix='/foo/'
then the iterator will only cycle through the keys
that begin with
the string '/foo/'.
:type delimiter: string
:param delimiter: can be used in conjunction with the prefix
to allow you to organize and browse your keys
hierarchically. See:
http://docs.amazonwebservices.com/AmazonS3/2006-03-01/
for more details.
:type marker: string
:param marker: The "marker" of where you are in the result set
:rtype: :class:`boto.s3.bucketlistresultset.BucketListResultSet`
:return: an instance of a BucketListResultSet that handles paging, etc
"""
return BucketListResultSet(self, prefix, delimiter, marker, headers)
----
Stephen Depooter
<
sb...@woot.net>