S3Upload generates a HTML POST Form that allows a user to select a file and upload directly to an Amazon S3 Bucket. This extension requires the ES3 extension to work.
This requires the ES3 extension to be installed and configured (as per that extension.)
Download and install in the extensions folder, and in your main.php configuration file add the following to the components array.
'components'=>array( 's3upload' => array( 'class'=>'ext.s3upload.CS3Upload', 'aKey' => <AWS Access key>, 'sKey' => <AWS Secret key>, 'bucket' => <Default Bucket>, ), ...
Then in the form where you want the upload buttons to appear, insert the following line.
echo Yii::app()->s3upload->Form($bucket, $uri, $redirect, $maxFileSize);
The parameters are:
On a successful upload, if you redirect to a URL rather than returning a 200/201 success code, you will get a url in the address bar similar to:
myurl/controller/action?bucket=yourbucket&key=filepath&etag="somehexstring"
In your controller you can use the following code to get the full filepath of the file in S3.
if (isset($_GET['key'])) { $model->file_location = $_GET['key']; }
An Amazon article about how to use HTML POST to upload a file directly to S3
Be the first person to leave a comment
Please login to leave your comment.