Adding folders programmatically in S3 using the AWS SDK for PHP

I use the AWS SDK for PHP, specifically part of Amazon S3, and I'm not quite sure where to start. The CMS I'm developing includes the ability to manage files both locally and remotely using an S3 account. I want administrators to be able to create folders in the S3 bucket, but since S3 is a file system with a flat file, I'm not sure how to create an empty “folder” or at least an empty object that looks like one. The manual I was reading (dated 2009) mentioned the suffix of the name of the object with _$folder$, but I tried this and it doesn't seem to work.

It should be possible to create empty folders in the S3 bucket since the AWS console has the ability to do this, so what is the method for creating empty folders in Amazon S3?

+3
source share
1 answer

The AWS Console seems to be creating empty folders, creating a file with 0 bytes that ends with the '/' character

for example, PUT a 0-byte file named ThisisAnEmptyFolder /

Then, when listing objects in a folder, the aws tools you use can return a “file” called ThisisAnEmptyFolder / - which users will not want to see. Thus, you may need to enable logic (for example, this is not PHP!)

if (object.key != prefix)
    show the file to the user
+9
source

Source: https://habr.com/ru/post/1792084/


All Articles