Ruby on rails 回形针缺少Amazon S3的协议(https)
在production.rb中:Ruby on rails 回形针缺少Amazon S3的协议(https),ruby-on-rails,paperclip,Ruby On Rails,Paperclip,在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')
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'),
}
}
我在初始化器/paperclip.rb中没有任何内容
在我的模型中:
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
为什么缺少HTTPS协议?这会使我的android应用程序崩溃,因为它需要一个连接到URL的协议。我需要硬编码URL还是回形针可以处理这个问题?您需要明确地将协议添加到配置中:
:s3_protocol => :https
您需要在
回形针
配置中指定方案,如下所示:
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'),
}
}
config.paperclip\u默认值={
s3_主机名称:“s3.#{ENV.fetch('AWS_REGION')}.amazonaws.com”,
存储::s3,
:s3_protocol=>:https,#:https
将方案https
分配给为您的amazon s3资产生成的url。有关更多详细信息,请参阅。这不提供问题的答案。若要评论或要求作者澄清,请在其帖子下方留下评论。-这确实提供了问题的答案,请参阅不管有没有详细说明,我都把答案贴了出来。
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'),
}
}