Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 云面+;卡里尔瓦夫_Ruby On Rails_Amazon Web Services_Ruby On Rails 4_Carrierwave_Fog - Fatal编程技术网

Ruby on rails 云面+;卡里尔瓦夫

Ruby on rails 云面+;卡里尔瓦夫,ruby-on-rails,amazon-web-services,ruby-on-rails-4,carrierwave,fog,Ruby On Rails,Amazon Web Services,Ruby On Rails 4,Carrierwave,Fog,所以这看起来应该很容易。。。每个人都说只要使用config.asset\u host。不过,当我设置这个值时,我的应用程序中的所有链接仍然指向S3 CarrierWave.configure do |config| config.storage = :fog config.fog_credentials = { :provider => 'AWS', :aws_access_key_id => AWS_ACCESS_KEY

所以这看起来应该很容易。。。每个人都说只要使用
config.asset\u host
。不过,当我设置这个值时,我的应用程序中的所有链接仍然指向S3

CarrierWave.configure do |config|

  config.storage = :fog

  config.fog_credentials = {
    :provider              => 'AWS',
    :aws_access_key_id     => AWS_ACCESS_KEY_ID,
    :aws_secret_access_key => AWS_SECRET_ACCESS_KEY,
    :region                => 'us-east-1'
  }

  config.fog_authenticated_url_expiration = 3.hours

  config.asset_host     = "http://xyz123.cloudfront.net"
  config.fog_directory  = S3_BUCKET_NAME
  config.fog_public     = false
  config.fog_attributes = {
    'Cache-Control' => "max-age=#{1.year.to_i}"
  }
end
以下是我如何称呼我的文件

image\u标签簿.attachments.first.filename.file.authenticated\u url(:thumb175)


在我看来,它像是
public\u url
预先设置了正确的主机,但它需要0个参数。。。那么,我应该如何传递正确的
响应内容配置
响应内容类型
以及链接过期时间呢?

我想你自己找到了,但是公共URL不会过期。如果您想这样做,您需要使用经过身份验证的URL。对于公共url,我认为您可以简单地获取url并附加您想要的任何查询参数,至少现在是这样。如果这对您来说很好,我们当然可以看到如何通过修补来做正确的事情。

我想您自己会发现这一点,但是公共URL不会过期。如果您想这样做,您需要使用经过身份验证的URL。对于公共url,我认为您可以简单地获取url并附加您想要的任何查询参数,至少现在是这样。如果这对您很有效,我们当然可以看到如何通过修补来做正确的事情。

我也有同样的问题,花了太长时间才找到答案!事实证明,当您设置fog\u public=false时,CarrierWave将忽略config.asset\u host。您可以通过设置config.fog\u public=true来演示这一点:您的URL现在将是CloudFront URL,而不是S3 URL。这个问题以前曾提出过:

在最近的一个项目中,我很高兴使用CarrierWave处理到S3的上传,但希望它在使用Model.attribute_URL时返回一个签名的CloudFront URL。我提出了以下(无可否认是丑陋的)解决方法,我希望其他人能够从中受益或改进:

将gem添加到项目中,并按照说明进行配置。然后在config/initializers中的新文件中添加以下对/lib/carrierwave/uploader/url.rb的覆盖(注意多次插入AWS::CF::Signer.sign\u url):

然后通过将以下内容添加到同一文件的底部来覆盖/lib/carrierwave/storage/fog.rb

require "fog"

module CarrierWave
  module Storage
    class Fog < Abstract
       class File
          include CarrierWave::Utilities::Uri
          def url
             # Delete 'if statement' related to fog_public
             public_url
          end
       end
    end
  end
end
需要“雾”
模块载体波
模块存储
类雾
最后,在config/initializers/carrierwave.rb中:

module CarrierWave
      module Uploader
        module Url
          extend ActiveSupport::Concern
          include CarrierWave::Uploader::Configuration
          include CarrierWave::Utilities::Uri

          ##
          # === Parameters
          #
          # [Hash] optional, the query params (only AWS)
          #
          # === Returns
          #
          # [String] the location where this file is accessible via a url
          #
          def url(options = {})
            if file.respond_to?(:url) and not file.url.blank?
              file.method(:url).arity == 0 ? AWS::CF::Signer.sign_url(file.url) : AWS::CF::Signer.sign_url(file.url(options))
            elsif file.respond_to?(:path)
              path = encode_path(file.path.gsub(File.expand_path(root), ''))

              if host = asset_host
                if host.respond_to? :call
                  AWS::CF::Signer.sign_url("#{host.call(file)}#{path}")
                else
                  AWS::CF::Signer.sign_url("#{host}#{path}")
                end
              else
                AWS::CF::Signer.sign_url((base_path || "") + path)
              end
            end
          end

        end # Url
     end # Uploader
end # CarrierWave
config.asset_host=“”

config.fog_public=false


就这样。您现在可以使用Model.attribute\u url,它会将签名的CloudFront url返回到CarrierWave上载到S3存储桶的私有文件。

我也遇到了同样的问题,花了太长时间才找到答案!事实证明,当您设置fog\u public=false时,CarrierWave将忽略config.asset\u host。您可以通过设置config.fog\u public=true来演示这一点:您的URL现在将是CloudFront URL,而不是S3 URL。这个问题以前曾提出过:

在最近的一个项目中,我很高兴使用CarrierWave处理到S3的上传,但希望它在使用Model.attribute_URL时返回一个签名的CloudFront URL。我提出了以下(无可否认是丑陋的)解决方法,我希望其他人能够从中受益或改进:

将gem添加到项目中,并按照说明进行配置。然后在config/initializers中的新文件中添加以下对/lib/carrierwave/uploader/url.rb的覆盖(注意多次插入AWS::CF::Signer.sign\u url):

然后通过将以下内容添加到同一文件的底部来覆盖/lib/carrierwave/storage/fog.rb

require "fog"

module CarrierWave
  module Storage
    class Fog < Abstract
       class File
          include CarrierWave::Utilities::Uri
          def url
             # Delete 'if statement' related to fog_public
             public_url
          end
       end
    end
  end
end
需要“雾”
模块载体波
模块存储
类雾
最后,在config/initializers/carrierwave.rb中:

module CarrierWave
      module Uploader
        module Url
          extend ActiveSupport::Concern
          include CarrierWave::Uploader::Configuration
          include CarrierWave::Utilities::Uri

          ##
          # === Parameters
          #
          # [Hash] optional, the query params (only AWS)
          #
          # === Returns
          #
          # [String] the location where this file is accessible via a url
          #
          def url(options = {})
            if file.respond_to?(:url) and not file.url.blank?
              file.method(:url).arity == 0 ? AWS::CF::Signer.sign_url(file.url) : AWS::CF::Signer.sign_url(file.url(options))
            elsif file.respond_to?(:path)
              path = encode_path(file.path.gsub(File.expand_path(root), ''))

              if host = asset_host
                if host.respond_to? :call
                  AWS::CF::Signer.sign_url("#{host.call(file)}#{path}")
                else
                  AWS::CF::Signer.sign_url("#{host}#{path}")
                end
              else
                AWS::CF::Signer.sign_url((base_path || "") + path)
              end
            end
          end

        end # Url
     end # Uploader
end # CarrierWave
config.asset_host=“”

config.fog_public=false

就这样。您现在可以使用Model.attribute_url,它会将一个签名的CloudFront url返回到CarrierWave上传到S3存储桶的私有文件中