s3assetmanager

A asset manager that stores content in the Amazon AWS S3.
14 followers

This extension serves as a replacement for the class CAssetManager. It publishes content on the Amazon AWS S3, allowing you to enable and use a CloudFront CDN for your assets.

Requirements

  • A cache component set.
  • An account on Amazon AWS S3

Usage

To install just unzip into the protected folder . Warning! I used as a basis the extension ES3, so if you have it installed you may have name conflicts.

Basic configuration:

'components' = array(
        ......
 
        'cache'=>array(
            'class'=>'system.caching.CMemCache',
            'servers'=>array(
                array('host'=>'localhost', 'port'=>11211),
            ),
        ),
        's3' => array(
            'class' => 'ext.s3.ES3',
            'aKey'=>'ADD YOUR AKEY HERE', 
            'sKey'=>'ADD YOUR SKEY HERE',
        ),
        'assetManager' => array(
            'class' => 'S3AssetManager',
            'host' => 'Your-bucket.s3.amazonaws.com', // changing this you can point to your CloudFront hostname
            'bucket' => 'Your-bucket',
            'path' => 'assets', //or any other folder you want
        ),
 
        ......
    )

Done! Your assets will be stored on Amazon!

Resources

Total 3 comments

#7520 report it
DarkNSF at 2012/03/27 07:43pm
Almost!

For some reason Chrome requires the contentType to be 'text/css' to load properly, the asset manager uploads everything as 'text/plain'. Also, I kept having filename issue on uploading deep asset directories.

Here are my changes:

S3AssetManager.publish()

if (is_file($src))

$contentType = CFileHelper::getMimeTypeByExtension($dstFile); 
if ($this->getS3()->putObjectFile($src, $this->bucket, $dstFile, S3::ACL_PUBLIC_READ, array(), $contentType))

AND

else if (is_dir($src))

$dstFile = $this->getBasePath().'/'.$dir.'/'.str_replace($src.DIRECTORY_SEPARATOR, '', $file);
$dstFile = str_replace('\\', '/', $dstFile); // windows xampp fix?
$contentType = CFileHelper::getMimeTypeByExtension($dstFile);
if (!$this->getS3()->putObjectFile($file, $this->bucket, $dstFile, S3::ACL_PUBLIC_READ, array(), $contentType))
#6492 report it
metzen at 2012/01/13 01:49pm
Thanks haykelbj!

Thank you Haykelbj!

Already correct and upload the extension.

I did not use the extension 'ES3' because it does not provide public access to all methods of S3 class (or at least I did not see how to access it).

#6491 report it
haykelbj at 2012/01/13 01:28pm
Missing 'if'-statement

Wow! I was about to implement this extension. Thanks!

I have just looked at the code on github and I noticed that the function S3AssetManager::getS3() is missing an if-statement:

private function getS3()
{
    throw new CException('You need to configure the S3 component or set the variable s3Component properly');
    return Yii::app()->{$this->s3Component};
}

missing line before 'throw':

if (!Yii::app()->{$this->s3Component})

One question: Is there a special reason why you did not use the 'es3' extension?

Thanks.

Leave a comment

Please to leave your comment.

Create extension