在production.rb中:
config.paperclip_defaults = {
s3_host_name: "s3.#{ENV.fetch('AWS_REGION')}.amazonaws.com",
storage: :s3,
s3_credentials: {
bucket: ENV.fetch('S3_BUCKET_NAME'),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
s3_region: ENV.fetch('AWS_REGION'),
}
}我在初始化器/剪纸中没有任何东西。
在我的模型中:
class MyModel < ApplicationRecord
has_attached_file :photo, styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
}
validates_attachment_content_type :photo, content_type: /\Aimage\/.*\Z/
def photo_url=(url)
self.photo = URI.parse(url)
end
end然后我检验一下:
m = Model.new
m.photo_url = "https://s3.us-east-2.amazonaws.com/mybucket/sports-grill-miami.jpg"
m.save!
m.photo.url(:thumb)
"//s3.us-east-2.amazonaws.com/mybucket/buckets/photos/000/000/005/thumb/sports-grill-miami.jpg?1495237443" 为什么HTTPS协议丢失了?这破坏了我的android应用程序,因为它需要一个连接到URL的协议。我需要硬编码的URL还是剪纸能处理这一点?
发布于 2017-05-20 00:28:14
您需要将协议显式添加到您的配置中:
:s3_protocol => :https发布于 2017-05-20 04:29:26
您需要在paperclip配置上指定方案如下:
config.paperclip_defaults = {
s3_host_name: "s3.#{ENV.fetch('AWS_REGION')}.amazonaws.com",
storage: :s3,
:s3_protocol => :https, # <- added this
s3_credentials: {
bucket: ENV.fetch('S3_BUCKET_NAME'),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
s3_region: ENV.fetch('AWS_REGION'),
}
}:s3_protocol => :https将将该方案https分配给为您的亚马逊s3资产生成的url。有关详细信息,请参阅文档。
https://stackoverflow.com/questions/44080512
复制相似问题