How to use amazon s3 with my existing app?

360 views
Skip to first unread message

hopewise

unread,
May 27, 2014, 12:35:56 PM5/27/14
to alche...@googlegroups.com
Although I have found this example: https://github.com/robinboening/alchemy3_s3_example
But, I am not sure the code required to start using amazon s3 buckets?

I've added gem 'dragonfly-s3_data_store' to Gemfile and added alchemy_s3.rb with my own keys to initializers folder, but still I can't upload an image to s3 bucket.

Is there other configurations that I have to do?

Jon Wu

unread,
May 27, 2014, 12:41:30 PM5/27/14
to alche...@googlegroups.com
I've got something like this in a dragonfly.rb in my app that overrides the one in the Alchemy gem and it's been working like a charm. Note that this is for Dragonfly 1.0 / Alchemy 3 and won't work directly with older Dragonfly / Alchemy 2.x.

Note that I've added far futures headers also. I modified our Alchemy fork to serve images directly from CloudFront (which pulls from S3) for non-cropped images. This makes the app so much faster since the backend isn't being tied up with image requests that are merely proxying the images.

# Alchemy CMS Dragonfly configuration.

# Upload files to S3 support Heroku (no local file storage) and clustering.
# Used in all environments so the database can be migrated between them without breaking images.
require 'dragonfly/s3_data_store'

# Pictures
Dragonfly.app(:alchemy_pictures).configure do
  plugin :imagemagick
  datastore :s3,
            bucket_name: 'your-bucket-name',
            access_key_id: ENV['S3_ACCESS_KEY_ID'],
            secret_access_key: ENV['S3_SECRET_ACCESS_KEY'],
            store_meta: false,
            storage_headers: {
              'Cache-Control' => 'public, max-age=31536000',
              'x-amz-acl' => 'public-read'
            }
  url_format '/pictures/:job/:basename.:format'
  url_path_prefix Alchemy::MountPoint.get
end

# Attachments
Dragonfly.app(:alchemy_attachments).configure do
  datastore :s3,
            bucket_name: 'your-bucket-name',
            access_key_id: ENV['S3_ACCESS_KEY_ID'],
            secret_access_key: ENV['S3_SECRET_ACCESS_KEY'],
            store_meta: false,
            storage_headers: {
              'Cache-Control' => 'public, max-age=31536000',
              'x-amz-acl' => 'public-read'
            }
end

# Logger
Dragonfly.logger = Rails.logger

# Add model functionality
if defined?(ActiveRecord::Base)
  ActiveRecord::Base.extend Dragonfly::Model
  ActiveRecord::Base.extend Dragonfly::Model::Validations
end



--
You received this message because you are subscribed to the Google Groups "Alchemy CMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to alchemy-cms...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeff Squires

unread,
Oct 21, 2015, 1:48:07 PM10/21/15
to Alchemy CMS
For any googlers out there, I desperately searched for the branch that Jon Wu mentioned with the fix but couldn't find it.

I ended up modifying EssencePicture like:

    def picture_url(options = {})
      return if picture.nil?
      # routes.show_picture_path(picture_params(options))
      Dragonfly.app(:alchemy_pictures).remote_url_for content.essence.picture.image_file.send(:uid)
    end

And it works!  This simply causes the url writting in the img src=.... to be the raw uploaded image, so the alchemy app will not be accessed when fetching the image (ideal for high-traffic sites.

Jon Wu

unread,
Oct 21, 2015, 5:15:05 PM10/21/15
to alche...@googlegroups.com
Sorry you couldn't find it! However, yup that's it and it does the job.

Since then, I've recently done something similar but rewritten the remote URL to use https://www.imgix.com to proxy the images. With that and Client Hints + imgix.js, the images come from a CDN, but also sent to each client in the best format (such as webp or JPEG XR) and get sent at the correct size. I'm in now way affiliated with imgix but we've been using it and the support team has been great too.

You could also use it crop or resize images at scale if needed too using the same sort of data that Dragonfly was using.

--
You received this message because you are subscribed to the Google Groups "Alchemy CMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to alchemy-cms...@googlegroups.com.

Thomas von Deyen

unread,
Oct 22, 2015, 4:17:02 AM10/22/15
to alche...@googlegroups.com
This looks really nice.

Maybe we could add Image rendering/processing endpoints into Alchemy as plugins.

So, that services like https://www.imgix.com could be more easily integrated.

Any volunteers? :)

regard

thomas

Jon Wu

unread,
Oct 27, 2015, 11:14:16 PM10/27/15
to alche...@googlegroups.com
That would be a cool idea! Wouldn't be able to work on that right now but would be happy to provide feedback or ideas if somebody works on it.

Right now, I just override the essence picture view to pass certain params through to imgix but still use Dragonfly on the backend to power thumbnails and such. There's no reason not to in admin. Now that most of our content is responsive, I'm rarely even using stuff like cropping or if I do, it's hard coded in my element logic to fit our design. Being able to swap in other services might be a nice thing, but it wouldn't add much for my current use cases overall. Wonder about others though...

Jon

Reply all
Reply to author
Forward
0 new messages