title: Using Paperclip, Fog, and Ceph
body: <p>I'm writing a Rails 3 app that uses Paperclip to transcode a video file attachment into a bunch of other formats, and then to store the resulting files. It all works fine for local storage, but I am trying to make it work using Paperclip's Fog support to store files in a bucket on our own Ceph cluster. However, I can't seem to find the right configuration options to make Fog talk to my Ceph server. </p>
  
  <p>Here is a snippet from my Rails class:</p>
  
  <pre><code>has_attached_file :videofile,
    :storage =&gt; :fog,
    :fog_credentials =&gt; { :aws_access_key_id =&gt; 'xxx', :aws_secret_access_key =&gt; 'xxx', :provider =&gt; 'AWS'},
    :fog_public =&gt; true,
    :url =&gt; ":id/:filename",
    :fog_directory =&gt; 'replay',
    :fog_host =&gt; 'my-hostname',
  </code></pre>
  
  <p>Writes using this setup fail because Paperclip attempts to save to Amazon S3 rather than the host I've provided. I have a non-Rails / non-Paperclip toy script working just fine:</p>
  
  <pre><code>conn = Fog::Storage.new({
     :aws_access_key_id =&gt; 'xxx',
     :aws_secret_access_key =&gt; 'xxx',
     :host =&gt; 'my-hostname',
     :path_style =&gt; true,
     :provider =&gt; "AWS",
  })
  </code></pre>
  
  <p>This correctly connects to my local Ceph server. So I suspect there is something I'm not configuring in Paperclip properly - but what? </p>
  
  <p>Here's the relevant hunk from fog.rb that I think is causing the connection to only go to AWS:</p>
  
  <pre><code>def host_name_for_directory
          if @options[:fog_directory].to_s =~ Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
            "#{@options[:fog_directory]}.s3.amazonaws.com"
          else
            "s3.amazonaws.com/#{@options[:fog_directory]}"
          end
        end
  </code></pre>