Configuration Problem

25 views
Skip to first unread message

Travis Sperry

unread,
Jan 31, 2016, 7:56:01 PM1/31/16
to Dragonfly
I'm having troubles setting my config files. When I run everything through the console the uploads to S3 work just fine **no errors**, so I know the initialization is happening and I have the keys set correctly. When I try to run things through the web server I get this error:

You need to configure Dragonfly::S3DataStore with access_key_id


Why will it process the uploads via console but not from the model?

Here are my initializers

# config/initializers/dragonfly.rb

require 'dragonfly'

# Configure
Dragonfly.app.configure do
  plugin :imagemagick

  protect_from_dos_attacks true
  secret "203abc7fb6b4020efec5da25c5026525a7cfd56b3f5b5420bd54e3defd6bc10e"

  url_format "/media/:job/:name"

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

#config/initializers/dragonfly_s3.rb

if Rails.env.development?
  bucket_name = "whatever"
else
  bucket_name = "whatever2"
end

Dragonfly.app.configure do
  datastore :s3,
    bucket_name: bucket_name,
    access_key_id: ENV['S3_CAMPS_ACCESS_KEY_ID'],
    secret_access_key: ENV['S3_CAMPS_SECRET_ACCESS_KEY']
end


Here's the call via the model:

class CouponCode < ActiveRecord::Base

  extend Dragonfly::Model
  dragonfly_accessor :image

  def generate_share_image
    # Read coupon.svg file
    file = File.read('app/assets/images/coupons/coupon.svg')

    #create custom coupon code using last name of parent
    coupon_code = name

    # Add custom coupon code to coupon.svg information
    file = file.gsub('CouponCode', coupon_code)

    # create new file and add edited info
    File.open('tmp/coupon.svg', 'w'){ |f| f.write(file) }
    new_file = File.open('tmp/coupon.svg')

    #save to s3
    result = Dragonfly.app.store(new_file, {}, path: "images/#{coupon_code}.svg", headers: {'x-amz-acl' => 'public-read-write'})

    update_attribute :image_uid, result

    File.delete(new_file)

    result
  end
end

Do I need to add something to allow the model to access Dragonfly after it's been initialized?  Users are not uploading images per the normal implementation. Instead, an image is being changed and uploaded to S3 each time a record is created.

Mark Evans

unread,
Feb 1, 2016, 6:44:39 AM2/1/16
to dragonf...@googlegroups.com
I can only imagine ENV['S3_CAMPS_ACCESS_KEY_ID’] isn’t set when you run the web server.
I don’t know your deployment process, but you’ll need to make sure the ENV is set properly (you could do a quick check with “raise ENV.inspect” or something)
Reply all
Reply to author
Forward
0 new messages