Paperclip 缺少与 Amazon S3 的协议 (https) [英] Paperclip is missing the Protocol (https) with Amazon S3
本文介绍了Paperclip 缺少与 Amazon S3 的协议 (https)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 production.rb 中:
In 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'),
}
}
我在 initializers/paperclip.rb 中没有任何内容.
I don't have anything in the initializers/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
然后我测试一下:
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 进行硬编码还是 Paperclip 可以处理这个问题?
Why is the HTTPS protocol missing? This is crashing my android application because it requires a protocol to connect to URL. Do I need to hardcode the URL or can Paperclip handle this?
推荐答案
您需要将协议显式添加到您的配置中:
You need to explicitly add the protocol to your configuration:
:s3_protocol => :https
这篇关于Paperclip 缺少与 Amazon S3 的协议 (https)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文