1

이렇게 이것은 아주 쉬워야하는 것처럼 보입니다 ... 모두는 그냥 config.asset_host을 사용하는 것입니다. 그래도 설정하면 내 앱의 모든 링크가 여전히 S3를 가리 킵니다. 그래서 어떻게 생각 해요 ... 내 파일을 호출하는 방법을 여기Cloudfront + Carrierwave

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 

그것은 public_url 적절한 호스트를 앞에 추가처럼 나에게 보이는

image_tag book.attachments.first.filename.file.authenticated_url(:thumb175)

...이지만, 0 인수를 적절한 response-content-dispositionresponse-content-type과 링크 만료 시간을 전달 하시겠습니까?

답변

0

본인이 직접 찾은 것으로 생각되지만 공개 URL은 만료되지 않습니다. 원하는 경우 인증 된 URL을 사용해야합니다. 공개 URL의 경우 최소한 URL을 가져와 원하는 검색어 매개 변수를 추가하면됩니다. 그게 잘 작동한다면, 우리는 옳은 일을하도록 패치하는 것에 대해 확실히 볼 수 있습니다.

1

나는 똑같은 문제가있어서 대답을 너무 오랫동안 보냈다! 설정했을 때 밝혀졌습니다 fog_public = false CarrierWave는 config.asset_host을 무시합니다. config.fog_public = true으로 설정하면 URL이 S3 URL이 아닌 CloudFront URL이됩니다. 내가 S3에 업로드되는 동영상을 처리 할 수 ​​CarrierWave를 사용하여 행복했다 최근 프로젝트에서

https://github.com/carrierwaveuploader/carrierwave/issues/1158 https://github.com/carrierwaveuploader/carrierwave/issues/1215

을하지만, Model.attribute_url를 사용할 때 서명 된 CloudFront를 URL을 반환하고 싶었 :이 문제는 이전에 제기되고있다. 나는 다른 사람들이 도움이되거나 개선 될 수 있기를 희망하는 다음과 같은 (틀린 추악한) 해결 방법을 생각해 냈습니다.

'cloudfront-signer' 보석을 프로젝트에 추가하고 지침에 따라 구성하십시오. 그런 다음설정/초기화에 새 파일 /lib/carrierwave/uploader/url.rb의 다음 재정의를 추가 (AWS :: CF의 다중 삽입주의 : Signer.sign_url) :

설정/초기화에,

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 

마지막 :

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 

그런 다음 같은 파일의 맨 아래에 다음을 추가하여 /lib/carrierwave/storage/fog.rb를 오버라이드 (override) S/carrierwave.rb :

config.asset_host = "http://d12345678.cloudfront.net"

config.fog_public = 거짓으로의

. 이제 Model.attribute_url을 사용할 수 있으며 서명 된 CloudFront URL을 CarrierWave가 S3 버킷에 업로드 한 개인 파일로 반환합니다.