我在 Heroku 上有一个应用程序,我正在使用 Amazon S3 来存储图像。我已经使用了我知道的所有缓存技术,但似乎图像加载速度太慢,这让一些用户望而却步。
目前用户得到
/media/W1siZiIsIjIwMTQvMDIvMjEvMjMvMjAvMDQvNTY1L01pa2VfOTIzMi5qcGciXV0/Mike_150.jpg?sha=d8993be2
根据说明一个必须使用
Dragonfly.app.remote_url_for(uid)
他们会得到
http://my-bucket.s3.amazonaws.com/2011/04/01/03/03/05/243/file.jpg
但是,当我添加此行时,没有任何反应。
#require 'dragonfly/s3_data_store'
require 'dragonfly'
# Configure
Dragonfly.app.configure do
plugin :imagemagick
protect_from_dos_attacks true
secret "2558d89a83f18f6da793e3b6dccc888c17642563e9ddedf456356f4c2d79"
url_format '/media/:job/:name'
response_header 'Cache-Control', 'public, max-age=3600' # You can set custom response headers
response_header 'Cache-Control' do |job, request, headers| # either directly or with a block
job.image? ? "public, max-age=10000000" : "private" # setting to nil removes the header
end
allow_legacy_urls true
if Rails.env.test? || Rails.env.development?
datastore :file,
root_path: Rails.root.join('public/system/dragonfly', Rails.env),
server_root: Rails.root.join('public')
else
datastore :s3,
bucket_name: ENV['S3_BUCKET_NAME'],
access_key_id: ENV['S3_KEY'],
secret_access_key: ENV['S3_SECRET'],
url_scheme: 'http',
url_host: 'mybucket.s3.amazonaws.com'
end
end
# Logger
Dragonfly.logger = Rails.logger
Dragonfly.app.remote_url_for(uid)
# Mount as middleware
Rails.application.middleware.use Dragonfly::Middleware
# Add model functionality
if defined?(ActiveRecord::Base)
ActiveRecord::Base.extend Dragonfly::Model
ActiveRecord::Base.extend Dragonfly::Model::Validations
end
- 我究竟做错了什么?
- 服务文件远程 url 会改变应用程序的性能吗?