简体   繁体   中英

Using Paperclip, Fog, and Ceph

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.

Here is a snippet from my Rails class:

has_attached_file :videofile,
  :storage => :fog,
  :fog_credentials => { :aws_access_key_id => 'xxx', :aws_secret_access_key => 'xxx', :provider => 'AWS'},
  :fog_public => true,
  :url => ":id/:filename",
  :fog_directory => 'replay',
  :fog_host => 'my-hostname',

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:

conn = Fog::Storage.new({
   :aws_access_key_id => 'xxx',
   :aws_secret_access_key => 'xxx',
   :host => 'my-hostname',
   :path_style => true,
   :provider => "AWS",
})

This correctly connects to my local Ceph server. So I suspect there is something I'm not configuring in Paperclip properly - but what?

Here's the relevant hunk from fog.rb that I think is causing the connection to only go to AWS:

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

the error was just from an improperly configured Ceph cluster. For anyone who finds this thread, as long as you:

  1. Have your wildcard DNS set up properly for your Ceph frontend;
  2. Ceph configured to recognize as such
  3. Pass in :host in :fog_credentials , which would be the FQDN of the Ceph frontend
  4. :fog_host, which apparently needs to be the URL for your bucket, eg https://bucket.ceph-server.foobar.com.

Paperclip will work out of the box. I don't think that it is documented anywhere that you can use :host but it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM