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.
Requirements ¶
This requires the ES3 extension to be installed and configured (as per that extension.)
Usage ¶
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.
<?php echo Yii::app()->s3upload->Form($bucket, $uri, $redirect, $maxFileSize); ?>
The parameters are:
- $bucket - if left blank, the bucket specified in the config is used.
- $uri - the path that the file will be uploaded to in S3.
- $redirect - the url that will be redirected to on upload success.
- $maxFileSize - the maximum file size that will be processed.
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'];
}
Resources ¶
An Amazon article about how to use HTML POST to upload a file directly to S3
- Amazon AWS - Browser Uploads to S3 using HTML POST Forms
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.