如何通过PHP SDK在Amazon S3存储桶下创建文件夹?
I am developing an iPhone app to allow user upload photo and share. I want to use S3 to store uploaded images as well as processed images (foe example, thumbnail, reduced size image). I've installed AWS PHP SDK on my EC2 instance, my questions are: 1) Should photos uploaded from iPhone app go to a EC2 directory first, then copied over to S3 bucket, or it should directly uploaded to S3? 2) How can I create different folders under the S3 bucket through PHP SDK and how to read the files from the folder?
Thanks in advance!
我正在开发一个iPhone应用程序,允许用户上传照片和分享。 我想使用S3来存储上传的图像以及处理过的图像(例如,缩略图,缩小图像)。 我已经在我的EC2实例上安装了AWS PHP SDK,我的问题是: 1)从iPhone应用程序上传的照片首先要转到EC2目录,然后复制到S3存储桶,还是应该直接上传到S3? 2) 如何通过PHP SDK在S3存储桶下创建不同的文件夹以及如何从文件夹中读取文件? p>
提前致谢! p> div>
The answer can be found here: Direct upload to s3 without the use of a production server
-
I've never used the PHP SDK, but I was browsing through the AWS SDK for PHP 1.5.14 documentation and came across the following APIs that you will need to utilize:
a) create_object : You'll use this to put a object into a bucket. You'll specify the filename. You asked how you can create different folders: you will include the full path into the filename. For instance instead of naming the file "photo1.jpg", you would name it "user1/vacation/photo1.jpg".
b) get_object_list : This API will return to you a list of objects given some criteria. If you want to read all the objects from a particular folder, specify the prefix as the path to the folder. For instance, if I want to find all files in the folder "user1/vacation/", I would specify my prefix to be "user1/vacation/".
Yes , it is possible to create new folder using s3
sdk.
try bellow code
<?php
/* abc is the folder name */
$s3->putObject(array(
'Bucket' => $bucket,
'Key' => "abc/",
'Body' => "",
'ACL' => 'public-read'
));