PHP Classes

Amazon S3 supports pseudo subdirs

Recommend this page to a friend!

      Amazon S3 Stream Wrapper  >  All threads  >  Amazon S3 supports pseudo subdirs  >  (Un) Subscribe thread alerts  
Subject:Amazon S3 supports pseudo subdirs
Summary:You can have subdirs by using prefix field while listing bucket
Author:Kamil Szot
Date:2008-07-16 20:45:47
Update:2009-04-25 07:21:06

  1. Amazon S3 supports pseudo subdirs   Reply   Report abuse  
Picture of Kamil Szot Kamil Szot - 2008-07-16 20:45:47
Name of object in the bucket can contain /-s
You can store and retrieve objects with keys like "dir/subdir/file.txt"

You can also list only objects from bucket which keys start with "dir/subdir/"

I think you could support this easily and nicely in your wrapper.

I also suggest using exceptions (or at least E_USER_ERROR instead if you keep compatibility with php4). Currently used trigger_error (E_USER_NOTICE) is too weak, and returning false does not always work (i.e. with file_put_contents).

Now it is hard to do something depending on whether uploading file to amazon (using file_put_contents) succeeded or not. Plus lack of exceptions causes users of your class to write much code to check for failure.

Of course you might allow to select method of reporting errors via configuration option (for example some global constant or class static field).

It would also be nice to allow user to select default level of security for files written using standard flags like 'w' and 'wb', and to allow user to specify via confiugration additional headers for put files (like Expires and such).

Anyway, great job. You class is fantastic. It's hard to imagine better application for custom stream wrappers.

  2. Re: Amazon S3 supports pseudo subdirs   Reply   Report abuse  
Picture of Cesar D. Rodas Cesar D. Rodas - 2009-04-25 07:21:06 - In reply to message 1 from Kamil Szot

Sorry for the long delay of my answer, at the time I coded the class I didn't know that I was possible, but it is full supported for Amazon.

I'm planning to rewrite the whole class, separating the stream from the class, and improve its functionality.

In the actual version if you want to do you that you'll need to hack the code, by changing the method getPathNumberOfComponents() and it always must return 2.

Best regards,

PS: If you have any problem don't hesitate to publish it here, I promise fast response.