GithubHelp home page GithubHelp logo

cakes3's Introduction

DEPRECATED

As may be abundantly clear I am no longer maintaining this component. It will not be updated for CakePHP 3. It was a learning tool that some few people found useful, but moving forward I'd rather put my time into supporting one of the other S3 libraries on Packagist. Not only framework agnostic but reducing the number of S3 library clones by one.

I'll leave the repo up for posterity and anyone that is still relying on it.

CakeS3 Plugin for CakePHP 2.0

The CakeS3 plugin for CakePHP allows easy integration with an Amazon S3 instance to be dropped into your app.

Utilising tpyo's amazon-s3-php-class, which in his words is..

This class is a standalone Amazon S3 REST implementation for PHP 5.2.x (using CURL), that supports large file uploads and doesn’t require PEAR.

This means it can be dropped in and run on a variety of hosting platforms.

Installation

Do one of the following to use this plugin in your CakePHP 2.0 app

git clone https://[email protected]/fullybaked/CakeS3.git app/Plugin/CakeS3

or

git submodule add https://[email protected]/fullybaked/CakeS3.git app/Plugin/CakeS3

or

Just download the package and unzip it into your app/Plugin directory

Then remember to add the following to your Config/bootstrap.php

//Add the CakeS3 plugin
CakePlugin::load('CakeS3');

Setup

Add the following to your controller $components instance variable

// in controller components var
$components = array(
	'CakeS3.CakeS3' => array(
		's3Key' => 'YOUR_AMAZON_S3_KEY',
		's3Secret' => 'YOUR_AMAZON_S3_SECRET_KEY',
		'bucket' => 'BUCKET_NAME',
		'endpoint' => 's3.amazonaws.com' // [optional] Only required if your endpoint is not s3.amazonaws.com
	)
);

Or add the settings before invoking the Plugin in Config/bootstrap.php

//Add the CakeS3 plugin
Configure::write('CakeS3', array(
		's3Key' => 'YOUR_AMAZON_S3_KEY',
		's3Secret' => 'YOUR_AMAZON_S3_SECRET_KEY',
		'bucket' => 'BUCKET_NAME',
		'endpoint' => 's3.amazonaws.com' // [optional] Only required if your endpoint is not s3.amazonaws.com
		)
);
CakePlugin::load('CakeS3');

And in your controller, only include the Component name

$components = array(
	'CakeS3.CakeS3'
);

Usage

####List the contents of a bucket

$contents = $this->CakeS3->listBucketContents();

####List the contents of a path relative to the bucket i.e. a folder

$contents = $this->CakeS3->listFolderContents('path/relative/to/bucket/');

####Upload a file to S3

$response = $this->CakeS3->putObject('/path/to/local/file', 'path/relative/to/bucket/', [$permission]);

The response value is an array with the following values

array(
	'name' => [name of saved file],
	'url' => [path to the resource on S3],
	'size' => [size of the resource on S3]
)

Allowed $permission Values:

The allowed values for permissions are wrapped by the component and are accessed via a wrapper method

$this->CakeS3->permission('private');
$this->CakeS3->permission('public_read');
$this->CakeS3->permission('public_read_write');
$this->CakeS3->permission('authenticated_read');

Example:

$response = $this->CakeS3->putObject('/path/to/local/file', 'path/relative/to/bucket/', $this->CakeS3->permission('authenticated_read'));

####Accessing Files With authenticated_read Permission

$auth_path = $this->CakeS3->authenticateUrl($full_s3_path, [$lifetime]);

If a file is stored on S3 with authenticated_read permissions, it is only accessible via a secure token. This method generates a new URL to reach the resource with the correct token, and a time to live. The default is 30 seconds as generally the URL will be recreated on refresh, but not accessible if copied out of the app

####Delete a file from S3

$response = $this->CakeS3->deleteObject('path/relative/to/bucket/');

####Retrieve an object from S3 location

$object = $this->CakeS3->getObject('path/relative/to/bucket/', [$path_to_store_local_copy = false]);

####Retrieve information about an object on S3

$info = $this->CakeS3->getObjectInfo('path/relative/to/bucket/');

####Change the bucket name on the fly using method chaining

$response = $this->CakeS3->bucket('new_bucket')->{any_of_the_above_methods};

Features

  • List contents of given bucket
  • List folder contents within a bucket
  • Push files to a location on S3
  • Retrieve an object from S3
  • Retrieve information about an object from S3
  • Delete files from S3
  • Generate authenticated URL's for protected resources

Attribution

The S3 php class used by this plugin was developed by tpyo

Changelog

Version 0.5 - 7th May 2013 BACKWARDS INCOMPATIBLE CHANGES

  • Brought the component code in line with PSR coding standards (which means all method names have changed to camelCase)

Version 0.4 - 14th November 2012

  • putObject method modified to accept MIME type parameter

Version 0.3 - 17th October 2012

  • Added better access to permission types via wrapper method
  • Added support for accessing protected resources on S3 via authenticated URL's

Version 0.2 - 6th March 2012

  • Added get_object method
  • Added get_object_info method
  • Made the build_url_to_file method public

Contributions

Contributions are welcome. If you think you can improve this plugin, please fork the repo, add to it and send me a pull request. All accepted enhancement authors will be listed below.

License

Released under the MIT license.

cakes3's People

Contributors

fullybaked avatar hashmode avatar hughbertd avatar tim-cc avatar tsolar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cakes3's Issues

'authenticated-read' File - From View

Thankyou for this plugin, I found it quite easy to setup.

How do I go about accessing a file that has been put on Amazon S3 as 'authenticated-read' from the view page in my cakePHP app?

i.e. I want to loop through some database records matching the files I have uploaded. I can store the amazone file path in my database but still it is not accessible, I need it accessible only to the users in my system (it's part of an intranet)

e.g. ['DataFile']['s3_path'] = https://s3.amazonaws.com/mybucketname/filename.jpg

Thanks

upload file function "putObject" is not working with me

I am using it like this it return the response but no thing change in the bucket
$response = $this->S3->putObject($this->request->data['file']['tmp_name'], 'attachments/',$this->S3->permission('public_read'));

It return this but the file didn't uploaded
Array
(
[name] => attachments
[url] => https://s3.amazonaws.com/temraz/attachments/
[size] => 1104
)

and when I put a folder that not exist in the bucket it create the folder in the right path without upload the file

any help ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.