s3upload S3Upload generates a HTML POST Form that allows a user to select a file and upload directly to an Amazon S3 Bucket.

  1. Requirements
  2. Usage
  3. Resources

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

Forum Discussion

An Amazon article about how to use HTML POST to upload a file directly to S3

1 0
4 followers
858 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: John J
Created on: Aug 25, 2011
Last updated: 12 years ago

Downloads

show all

Related Extensions