【问题标题】:Fog directory appends local system path with amazon url when i try to give dynamic fog directory当我尝试提供动态雾目录时,雾目录会在本地系统路径中附加亚马逊 url
【发布时间】:2016-07-28 22:45:00
【问题描述】:

我正在将 FOG 与 Paperclip 一起使用。我添加了以下代码以提供动态目录名称。

fog_directory: proc { |file| file.instance.repo.name }

它正确创建了雾目录,但是当我尝试获取 url 时,它使用亚马逊 url 添加了本地系统路径。

https://s3.amazonaws.com/%23%3CProc:0x4ae8f3bb@/home/apple/projects/project.name/config/initializers/paperclip.rb:8%3E/abc.jpg

【问题讨论】:

  • 你能分享完整的回形针文件吗?

标签: amazon-s3 paperclip proc fog


【解决方案1】:

我通过覆盖 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

【讨论】:

    猜你喜欢
    • 2014-05-30
    • 2013-10-19
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    相关资源
    最近更新 更多