2

Does anybody know of a method to override/alter EE's native avatar uploading functionality (without hacking core) to upload to S3?

I've got a client site running on AWS' Elastic Beanstalk service, utilizing RDS for the DB storage, S3 and Cloudfront for all of the site's image content.

The client is wanting to launch forums as a new feature on the site, and while our existing infrastructure is well-suited for this, my main concern is user-uploaded images, like avatars or even custom image uploads.

Ideally I'd like to find some way to store these within an S3 bucket, since our EC2 instances only contain the site code, and anything uploaded to one server in the cluster won't be visible to the others, and will disappear when that instance gets terminated in the future for whatever reason.

Side note: I've heard it suggested that I instead create an independent EBS volume, and update my default AMI to mount that volume at startup so that all my instances will have access to the file store. I'd prefer to go the S3 route instead for performance reasons.

1

You can set file upload paths and preferences in your EE config.php file which should support a remote location like S3. You also have control over paths for avatars and user uploads here too. I set them by standard in my config:

// Member paths and URLs
$config['avatar_path']                  = $base_path . "/images/avatars/";
$config['avatar_url']                   = $base_url . "/images/avatars/";
$config['photo_path']                   = $base_path . "/images/member_photos/";
$config['photo_url']                    = $base_url . "/images/member_photos/";
$config['sig_img_path']                 = $base_path . "/images/signature_attachments/";
$config['sig_img_url']                  = $base_url . "/images/signature_attachments/";
$config['prv_msg_upload_path']          = $base_path . "/images/pm_attachments/";

// Image paths and URLs
$config['captcha_path']                 = $base_path . "/images/captchas/";
$config['captcha_url']                  = $base_url . "/images/captchas/";
$config['emoticon_path']                = $base_url . "/images/smileys/";

I don't see any reason why you couldn't set a remote location to your S3 drive.

| improve this answer | |
  • This has occurred to me as well. The problem with this approach (I think) is that EE expects a path within the local file system; hence the distinction between settings for 'avatar_path' vs 'avatar_url'. Additionally, there would be no way here to tell EE what credentials to use to authenticate with the S3 bucket on AWS, as EE/PHP needs permissions to write to the file system. I wish it was as straightforward as you outlined, but I don't think it's possible. – Evan Rowe Mar 26 '13 at 19:41
  • True. I'd forgotten about the authentication requirement for S3 so yes that would cause an issue. In that case there's no native way to change the paths but because they are configurable it would theoretically be possible to create an extension or a bootstrap of some kind to load in the remote paths and script in the required authentication but it would take a bit of work. – Ian Mar 27 '13 at 8:28
1

Two ways:

  1. You could mount s3 using s3fs-fuse^ onto your structure, so EE would experience it as a local file-system and the URL could be the s3 bucket URL.
  2. Another way is to use aws s3 sync^^ to synchronise the upload/media folder with s3, that way EE just uses the local file-system and your visitors use s3.

^ https://github.com/s3fs-fuse/s3fs-fuse

^^ http://docs.aws.amazon.com/cli/latest/reference/s3/sync.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.