Amazon S3 is an online storage service that provides simple web service interface to store and retrieve data. This space has to be purchased.
This article covers uploading and deleting the files from Amazon S3 through Cakephp 2.2.2 Component. You can extend this component as per your requirement.
You can understand the usage of this component with the below mentioned steps:
1) Put AWS SDK in /app/Controller/Component folder. You can download the aws attached with this article, or you can download it as zip from http://docs.aws.amazon.com/aws-sdk-php/guide/latest/installation.html
2) Put AwsComponent.php file in /app/Controller/Component folder.
3) Configure your component in constructor of the component as :
$this->s3 = S3Client::factory(array(
'key' => YOUR_API_KEY,
'secret' => YOUR_API_SECRET,
'region' => 'eu-west-1',
));
4) Load component in controller e.g.
public $components = array("Aws");
5) Specify your bucket name in controller as :
$this->Aws->bucket = YOUR_BUCKET_NAME ;
or you can specify the bucket in the component by assigning YOUR_BUCKET_NAME in $bucket variable.
6) To upload a file on Amazon S3
$response = $this->Aws->upload($file) ;
7) To delete a file or multiple files:
$response = $this->Aws->delete(array(
array('Key' => $keyname1),
array('Key' => $keyname2),
array('Key' => $keyname3),
...
...
)) ;
Here keyname is the file which you want to delete.
8) To empty the particular folder :
$response = $this->Aws->emptyFolder($folder) ;
Great.Thanks for providing such a vital knowledge !!
Good explaination in simple and clean manner.