CarrierWave With Cloudfront 生成错误 URL
CarrierWave With Cloudfront Generating wrong URL
您好,我正在将 Cloudfront 与 CarrierWave 和 S3 结合使用。出于某种原因,在我的应用程序中,使用 image_tag 时,我的云端路径得到了非常奇怪的 URL,而且我不知道哪里出错了。这是我的载波配置文件
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws' # required
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: 'accesskey', # required
aws_secret_access_key: 'secretaccess key', # required
region: 'us-east-1', # optional, defaults to 'us-east-1'
}
config.fog_directory = 'bwautosales' # required
# config.asset_host = 'randomletters.cloudfront.net'
config.asset_host = 'randomletters.cloudfront.net'
config.fog_public = true
config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" } # optional, defaults to {}
end
和我的 production.rb 文件
config.action_controller.asset_host = 'randomletters.cloudfront.net'
但是在我的视图中当我做类似
的事情时
<%= link_to image_tag(car.images[0], class: "img-responsive right-block", id: index), car %>
我明白了 -
src = https://randomletters.cloudfront.net/images/randomletters.cloudfront.net/uploads/car/images/28/car.png"
我确定这很容易修复,但不知道哪里出错了。任何帮助将不胜感激!
图片上传器`
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_whitelist
%w(jpg jpeg gif png)
end
end
`
在您的 Carrierwave 初始化程序中更改行,
config.asset_host = 'randomletters.cloudfront.net'
到 config.asset_host = 'http://randomletters.cloudfront.net'
以获得所需的云端 URL。
您还可以从 Production.rb 中删除 config.action_controller.asset_host = 'randomletters.cloudfront.net'
行,因为载波本身是从云端获取的 url。
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws'
config.fog_credentials = {
--------------
--------------
}
config.fog_directory = 'bwautosales'
config.asset_host = 'http://randomletters.cloudfront.net' # please check the change in this line.
config.fog_public = true
config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" } # optional, defaults to {}
end
只是为了增加 Sravan 回答的可信度,我遇到了同样的问题,当我按照他的指示进行操作时,它开始正常工作。如果您从
中省略 http://
config.asset_host = <>
它感到困惑,并尝试对您网站的域名使用不同的路径。我有同样的问题,但在 url 的开头添加 http:// 修复了它。
您好,我正在将 Cloudfront 与 CarrierWave 和 S3 结合使用。出于某种原因,在我的应用程序中,使用 image_tag 时,我的云端路径得到了非常奇怪的 URL,而且我不知道哪里出错了。这是我的载波配置文件
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws' # required
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: 'accesskey', # required
aws_secret_access_key: 'secretaccess key', # required
region: 'us-east-1', # optional, defaults to 'us-east-1'
}
config.fog_directory = 'bwautosales' # required
# config.asset_host = 'randomletters.cloudfront.net'
config.asset_host = 'randomletters.cloudfront.net'
config.fog_public = true
config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" } # optional, defaults to {}
end
和我的 production.rb 文件
config.action_controller.asset_host = 'randomletters.cloudfront.net'
但是在我的视图中当我做类似
的事情时 <%= link_to image_tag(car.images[0], class: "img-responsive right-block", id: index), car %>
我明白了 -
src = https://randomletters.cloudfront.net/images/randomletters.cloudfront.net/uploads/car/images/28/car.png"
我确定这很容易修复,但不知道哪里出错了。任何帮助将不胜感激!
图片上传器`
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_whitelist
%w(jpg jpeg gif png)
end
end
`
在您的 Carrierwave 初始化程序中更改行,
config.asset_host = 'randomletters.cloudfront.net'
到 config.asset_host = 'http://randomletters.cloudfront.net'
以获得所需的云端 URL。
您还可以从 Production.rb 中删除 config.action_controller.asset_host = 'randomletters.cloudfront.net'
行,因为载波本身是从云端获取的 url。
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws'
config.fog_credentials = {
--------------
--------------
}
config.fog_directory = 'bwautosales'
config.asset_host = 'http://randomletters.cloudfront.net' # please check the change in this line.
config.fog_public = true
config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" } # optional, defaults to {}
end
只是为了增加 Sravan 回答的可信度,我遇到了同样的问题,当我按照他的指示进行操作时,它开始正常工作。如果您从
中省略 http://config.asset_host = <>
它感到困惑,并尝试对您网站的域名使用不同的路径。我有同样的问题,但在 url 的开头添加 http:// 修复了它。