Kevin's Worklog

Documenting the Daily Stream

Fixing CSS MIME Type for S3 Octopress

I’ve “rebooted” my worklog using Octopress and, at the same time, started publishing my site’s static output to S3. The problem, I’ve found, comes when I’m ready to deploy the Octopress site to S3. I’m using s3cmd to do the upload, and it’s configured in my Rakefile like:

s3_bucket = ""

task :s3 do
    puts "## Deploying website via s3cmd"
    ok_failed system("s3cmd sync --acl-public --reduced-redundancy public/* s3://#{s3_bucket}/")

The deployment works great, except my site shows up in the browser like it doesn’t have the CSS applied. After some digging, I discovered this is because s3cmd uploads the CSS file with the MIME type of text/plain instead of text/css. This seems to be the fault of python-magic. There is a patch that’s been merged in with the latest version of s3cmd, but UbuntuGnome hasn’t updated to it yet. So, the immediate (i.e., easiest) workaround is to just uninstall python-magic.

sudo aptitude remove python-magic

Once I do that, the upload to S3 via s3cmd works without a hitch. The mime-type is set correctly for CSS files as text/css. In the future, when my copy of s3cmd supports it, I’ll add the --no-mime-magic argument to the s3cmd command in my Octopress Rakefile.