Multisite, upload images directly to Amazon S3

I have created a multisite network but I’ve noticed people are uploading a lot of image files which are clogging up my server space.

Is there a way I can amend the default network theme (Users are limited to using 1 standard theme) so that all images are uploaded to my S3 account and then displayed as per usual in the WordPress media uploader?

Read More

I want to be able to do this automatically as oppose to having all my network’s users having to install a plugin manually as some of them aren’t exactly tech savvy.

Related posts

Leave a Reply

1 comment

  1. If you are running on a dedicated linux server and are comfortable with the command line, you could install s3fs. This is a program that allows you to actually mount your Amazon s3 Bucket as a directory on you server.

    In the standard multisite environment, media uploads for all sites but the main site are stored in the blogs.dir directory inside the wp-content directory. I am currently running a multisite installation where the blogs.dir IS my mounted s3 bucket. Here’s an overview…

    1. Rename the blogs.dir folder to _blogs.dir. (Note: this will temporarily make all multisite media files unaccessible).
    2. Create a new directory with the name blogs.dir.
    3. Install and use s3fs to mount your s3 bucket to the blogs.dir directory.
    4. Copy the contents of the _blogs.dir folder into the new blogs.dir. This will copy all files and folders directly to you s3 bucket. (It can take a while depending on the number of images).
    5. Once it is completed, go check the homepage of one of your user sites (not your main site) and make sure WordPress is able to read and display the images).
    6. Make sure that the bucket is mounted at boot in case you need to reboot your server. In linux this is often accomplished by adding an s3fs command to the /etc/fstab file.

    As with anything, there are pros and cons to this setup.

    The pros are that whenever a user uploads a media file to their multisite, it is being directly stored on your s3 bucket. And when the media is called for, it is being pulled from the bucket. Also, when a user edits an image inside the WordPress admin, the changes are again being stored directly in your s3 bucket.

    The cons are that it does make the upload new file interface a bit slower on the backend, and it may make reading the files a little slower also (unless you can use .htaccess rewrite rules in apache to redirect the media url’s directly to s3, which is possible, but beyond the scope of this answer).

    Hope this helps. Visit the s3fs for documentation on how to install and use s3fs.