简体   繁体   中英

Elfinder Rails and Amazon S3

I am using Elfinder Rails for Media Manger in my application. I am working on to store the media files to Amazon S3 storage. I try to use the gem el_finder_s3. I created bucket and provided all the configurations like.

  def elfinder
    ElFinderS3::Connector.new(
      :mime_handler => ElFinderS3::MimeType,
      :root => '/',
      :url => 's3.ap-southeast-1.amazonaws.com',
      :thumbs => true,
      :thumbs_size => 100,
      :thumbs_directory => 'thumbs',
      :home => t('admin.media.home'),
      :original_filename_method => lambda { |file| "#{File.basename(file.original_filename, File.extname(file.original_filename)).parameterize}#{File.extname(file.original_filename)}" },
      :default_perms => {:read => true, :write => true, :rm => true, :hidden => false},
      :server => {
        :bucket_name => 'bucket_name',
        :region => 'ap-southeast-1',
        :access_key_id => 'acces_key',
        :secret_access_key => 'secret_key',
        :cdn_base_path => 's3.ap-southeast-1.amazonaws.com'
      }
    ).run(params)
  end

Rails application is connect with S3 but elfinder doesn't show the file contents. I checked the bucket, thumb folder was created but elfinder was unable to load the contents. 屏幕截图

Please help me to fix it.

It is fixed with the update of the above script. Here is the updated script.

def elfinder
    h, r = ElFinderS3::Connector.new(
      :mime_handler => ElFinderS3::MimeType,
      :root => '/',
      :url => 's3.ap-southeast-1.amazonaws.com',
      :thumbs => true,
      :thumbs_size => 100,
      :thumbs_directory => 'thumbs',
      :home => t('admin.media.home'),
      :original_filename_method => lambda { |file| "#{File.basename(file.original_filename, File.extname(file.original_filename)).parameterize}#{File.extname(file.original_filename)}" },
      :default_perms => {:read => true, :write => true, :rm => true, :hidden => false},
      :server => {
        :bucket_name => 'bucket_name',
        :region => 'ap-southeast-1',
        :access_key_id => 'acces_key',
        :secret_access_key => 'secret_key',
        :cdn_base_path => 's3.ap-southeast-1.amazonaws.com'
      }
    ).run(params)
headers.merge!(h)

if r.empty?
  (render :nothing => true) and return
end

render :json => r, :layout => false
end

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