gpt4 book ai didi

ruby-on-rails - Carrierwave+fog+s3 不适用于 Cloud Front URL

转载 作者:行者123 更新时间:2023-12-04 06:01:09 24 4
gpt4 key购买 nike

我遇到了这个问题 carrierwave+fog+s3与亚马逊 cloud front .通过以下设置,我可以将文件上传到 s3,但上传后,我从 Rails 应用程序获取的 S3 对象 URL 没有 assets_host基于 URL,即我希望 URL 看起来像这种格式 https://mycloudfrontname.cloudfront.net/uploads/myfile.mp3
但它们都以这种格式出现https://mybucketname.s3.amazonaws.com/uploads/myfile.mp3
这里可能有什么问题?

CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'XXXX',
:aws_secret_access_key => 'XXXX',
:region => 'us-east-1'
}
config.fog_directory = 'mybucketname'
config.asset_host = 'https://mycloudfrontname.cloudfront.net'
config.fog_public = false
config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}
end

更新:

我从 Carrierwave 的 /lib/carrierwave/storage/fog.rb 中找到了这个代码位- 所以如果我们设置 asset_host就像上面的代码片段一样,这一定能正常工作吗?或者我还必须做任何其他配置吗?
def public_url
if host = @uploader.asset_host
if host.respond_to? :call
"#{host.call(self)}/#{path}"
else
"#{host}/#{path}"
end
else
# AWS/Google optimized for speed over correctness
case @uploader.fog_credentials[:provider]
when 'AWS'
# if directory is a valid subdomain, use that style for access
if @uploader.fog_directory.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\d{1,3}){3}$))(?:[a-z0-9\.]|(?![\-])|\-(?![\.])){1,61}[a-z0-9]$/
"https://#{@uploader.fog_directory}.s3.amazonaws.com/#{path}"
else
# directory is not a valid subdomain, so use path style for access
"https://s3.amazonaws.com/#{@uploader.fog_directory}/#{path}"
end
when 'Google'
"https://commondatastorage.googleapis.com/#{@uploader.fog_directory}/#{path}"
else
# avoid a get by just using local reference
directory.files.new(:key => path).public_url
end
end
end

最佳答案

更改 config.fog_publictrue并添加 config.asset_host = 'YOUR_CND_ADDRESS' . asset_host fog_public 时不起作用是假的

关于ruby-on-rails - Carrierwave+fog+s3 不适用于 Cloud Front URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13527968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com