我正在使用带Paperclip的FOG。我添加了以下代码来命名动态目录。
fog_directory: proc { |file| file.instance.repo.name }
它正确地创建了fog目录,但当我尝试获取url时,它添加了带有amazonurl的本地系统路径。
https://s3.amazonaws.com/%23%3CProc:0x4ae8f3bb@/home/apple/projects/project.name/config/initializers/paperclip.rb:8%3E/abc.jpg
我通过重写Paperclip模块来解决这个问题。
module Paperclip
module Storage
module Fog
def host_name_for_directory
if directory_name.to_s =~ Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
"#{directory_name}.s3.amazonaws.com"
else
"s3.amazonaws.com/#{directory_name}"
end
end
def directory
@directory ||= connection.directories.new(key: directory_name)
end
def directory_name
if @options[:fog_directory].respond_to?(:call)
@options[:fog_directory].call(self)
else
@options[:fog_directory]
end
end
end
end
end