开发者

Amazon s3 class by undesigned create folder

I am trying to use undesigned s3 class to create a folder. I can create just a folder in my amazon s3 account but just running the follow.

I can do this.

$file = "license.txt";  
if ($s3->putObjectFile($file, $_POST['bucket'], $_POST['folder']."/", S3::ACL_PUBLIC_READ)) {
        echo "File uploaded.";
} else {
        echo "Failed to upload file.开发者_StackOverflow中文版";
}

Which will create a folder in my bucket but when i run a loop it doesn't reference it as a folder

Any suggestions why???


S3 doesn't actually have folders.

Each bucket just contains your files which are referenced by their key/filename. There is a convention that if these filenames contain /'s then the text before each / is considered a folder and many of the GUI tools use this to display a folder hierachy.

eg A file with the name folder1/folder2/file.txt will appear to be 2 levels deep in folder1 and subfolder folder2.

Amazon also makes it easier to search you virtual folders using the delimiter and prefix parameters. See http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?RESTBucketGET.html


While S3 doesn't support directories they way they are generally thought of, they do support an interesting alternative.

If you PUT an object with no content (0 bytes), and the key (name) ends with a "/", and the "content-type" = "binary/octet-stream", it will be treated by S3 as a directory (folder).

Keep in mind, it is still just a file; however, the console will treat it as a directory (folder) and many SDK clients will treat it as a directory (folder).

In order to get your 0 bytes, you can simply use the file "/dev/null" instead of "license.txt".

In order to rename/copy/delete a directory, keep in mind, you will want to search for everything with that key prefix (you will get the directory object and any other objects with that directory path as the key prefix) -- You will need to copy those objects to objects with the new prefix (in cases of rename/delete, you will need to delete the old prefixes).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜