开发者

Adding folders programatically to S3 with the AWS SDK for PHP

I'm using the AWS SDK for PHP, specifically the Amazon S3 portion, and I'm not quite sure where to proceed. The CMS I'm developing includes the ability to manage files both locally and remotely using an S3 account. I want administra开发者_StackOverflow中文版tors to have the ability to create folders in the S3 bucket, but because S3 is a flat-file system, I'm not sure how to create an empty "folder", or at least a blank object that looks like one. A guide I was reading (dated 2009..) mentioned suffixing the object name with _$folder$, but I tried that and it doesn't seem to work.

It must be possible to create empty folders in an S3 bucket because the AWS console has the ability to do it, so what is the method for creating empty folders in Amazon S3?


It looks like the AWS Console creates empty folders by creating a 0 byte file that ends in a '/'

eg PUT a 0 byte file called ThisisAnEmptyFolder/

Then when listing the objects in a folder, the aws tools you use may return a 'file' called ThisisAnEmptyFolder/ - which users won't want to see. So you may need to include logic something like (this is NOT PHP!)

if (object.key != prefix)
    show the file to the user
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜