Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 SDK for PHP, Uploading to folders inside a bucket

I'm just getting started with the AWS S3 SDK for PHP, I've managed to upload a folder of items from my PC to an s3 bucket using PHP, is there any way to specify a folder inside that bucket, for example, instead of uploading image.jpg to imagebucket, it uploads to the folder called images inside 'imagebucket'.

like image 551
Jamie Taylor Avatar asked May 31 '12 13:05

Jamie Taylor


2 Answers

There is no concept of folders in aws s3. Its just for display purpose used by amazon AWS UI.

Actually it stores filename as key & data as value.

if you store 5 files with different folders, they are not going to create 5 folders.

like image 151
Mayur Kataria Avatar answered Nov 17 '22 05:11

Mayur Kataria


From the docs:

public function uploadDirectory($directory, $bucket, $keyPrefix = null, array $options = array())

By specifying $keyPrefix, you can cause the uploaded objects to be placed under a virtual folder in the Amazon S3 bucket. For example, if the $bucket name is my-bucket and the $keyPrefix is 'testing/', then your files will be uploaded to my-bucket under the testing/ virtual folder: https://my-bucket.s3.amazonaws.com/testing/filename.txt

See: http://docs.aws.amazon.com/aws-sdk-php/guide/latest/service-s3.html#uploading-a-directory-to-a-bucket

like image 27
supernifty Avatar answered Nov 17 '22 04:11

supernifty