I've successfully installed and uploaded images in my Rails app using the dragonfly gem. Loading images works fine if I load it directly through the app. However, if I load the images through Cloudfront, I get an error page that says "You need to give a SHA parameter" which is strange because the SHA is included in the URL already:
For context here's my dragonfly settings:
# config/initializers/dragonfly.rb
require 'dragonfly'
# Configure
Dragonfly.app.configure do
plugin :imagemagick
secret "randomsecret"
url_format "/media/:job/:name"
datastore :file,
root_path: Rails.root.join('public/system/dragonfly', Rails.env),
server_root: Rails.root.join('public')
end
# Logger
Dragonfly.logger = Rails.logger
# 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
I've already read the CDN section in the documentation of dragonfly, but it didn't fix the problem. The only difference it made is that it included the url_host
when calling image.url
instead of just the relative path that it normally returns.
By default, CloudFront does not forward query strings to the origin. Have you verified that you have query string forwarding enabled?