2017-08-24 133 views
0

我在我的應用程序中使用Elfinder Rails作爲媒體管理器。我正在努力將媒體文件存儲到Amazon S3存儲。我嘗試使用gem el_finder_s3。我創建了bucket並提供了所有的配置。Elfinder Rails和Amazon S3

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應用程序與S3連接,但elfinder不顯示文件內容。我檢查了桶,拇指文件夾已創建,但elfinder無法加載內容。 screen shot

請幫我解決它。

回答

0

它已修復上述腳本的更新。這是更新的腳本。

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