Cakephp Amazon S3 Save

An Amazon S3 component for CakePHP

Project README

Amazon S3 Plugin for CakePHP 2.x

A CakePHP Plugin to interact with Amazon Web Services S3 objects. This plugin provides a simple and robust methods that can be added to any CakePHP project to complete the following:

  • Retrieve a remote file from an S3 bucket and save locally
  • Save a local file in an S3 bucket
  • Delete a file in an S3 bucket

Requirements

Installation

[Manual]

[GIT Submodule]

In your app directory type:

git submodule add -b master git://github.com/robmcvey/cakephp-amazon-s3.git Plugin/AmazonS3
git submodule init
git submodule update

[GIT Clone]

In your Plugin directory type:

git clone -b master git://github.com/robmcvey/cakephp-amazon-s3.git AmazonS3

Usuage examples

Remember to add CakePlugin::load('AmazonS3'); to your app's bootstrap file.

Then, simply initialise the plugin with your AWS Access key, secret key and the bucket name you wish to work with.

App::uses('AmazonS3', 'AmazonS3.Lib');
$AmazonS3 = new AmazonS3(array('{access key}', '{secret key}', '{bucket name}'));

GET

The get method retrieves a remote file and saves it locally. So let's say there is the file foo.jpg on S3 and you want to save it locally in /home/me/stuff/photos you'd use the following.

$AmazonS3->get('foo.jpg' , '/home/me/stuff/photos');

PUT

The put method does the reverse of get, and saves a local file to S3.

$AmazonS3->put('/home/me/stuff/photos/foo.jpg');

You can optionally specifiy a remote directory within the bucket to save the file in. Be sure not to include a starting / in the remote directory string.

$AmazonS3->put('/home/me/stuff/photos/foo.jpg' , 'some/folder');

To add any additional AWS headers to a put, example to set the file as "public", they can be passed as an array to the amazonHeaders property.

$AmazonS3->amazonHeaders = array(
	'x-amz-acl' => 'public-read',
	'X-Amz-Meta-ReviewedBy' => '[email protected]'
);
$AmazonS3->put('/home/me/stuff/photos/foo.jpg' , 'some/folder');

DELETE

Deletes a file from S3.

$AmazonS3->delete('foo.jpg');

Or delete from within a directory in the bucket. Be sure not to include a starting / in the string or you will receive a SignatureDoesNotMatch error:

$AmazonS3->delete('some/folder/foo.jpg');
Open Source Agenda is not affiliated with "Cakephp Amazon S3" Project. README Source: robmcvey/cakephp-amazon-s3
Stars
35
Open Issues
5
Last Commit
8 years ago

Open Source Agenda Badge

Open Source Agenda Rating