Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

Commit

Permalink
Finally releasing a stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
nhocki committed Jun 15, 2011
1 parent 7ec15b0 commit 5f6b68a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
34 changes: 28 additions & 6 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
h2. Works only for Rails 3 (for now)

h1. Paperclip S3 Storage

This gem will force paperclip to store attachments on S3. It's great for "Heroku":http://heroku.com apps and thats basically why I wrote it.

I was really lazy writing this over and over again, so I just gemed it.
This gem will force paperclip to store attachments on S3 if your application is in production. It's great for "Heroku":http://heroku.com apps.

h1. Important Notes

If you're in fact using "Heroku":http://heroku.com, and you want the attachments to have custom paths. *PLEASE* do not use *RAILS_ROOT*. Why? Every time you deploy your app to "Heroku":http://heroku.com, you're changing the RAILS_ROOT, so all your uploaded files will be lost and your bucket *WILL* be a mess!

A default, Heroku-working path is on by default, so you can just use it.

h1. How to Use

This gem will read your S3 credentials from the server's environment. You will need to provide a secret key, an access key and a bucket. (You can provide an *_s3_credentials_* hash options with *_access_key_id_* and *_secret_access_key_* instead.)

If you are using "Heroku":http://heroku.com, it's really easy to do this, just

<pre>
heroku config:add S3_BUCKET=your_bucket_name
heroku config:add S3_KEY=your_access_key
heroku config:add S3_SECRET=your_secret_key
</pre>

Ok, if you're really lazy, you can do that in one line:

<pre>
heroku config:add S3_BUCKET=your_bucket_name S3_KEY=your_access_key S3_SECRET=your_secret_key
</pre>

After you've done this, you can use paperclip normally. The gem just extends this methods and changes the options to force the S3 Storage. You can *even* use the same options (like path, default_style, etc.)



h2. Contribute

Feel free to fork, fix/patch/extend this. Everything is welcome.
Feel free to fork, fix/patch/extend this. Everything is welcome.

h3. TODO

* Clean the Railtie, specially the Rails.env part.
11 changes: 5 additions & 6 deletions lib/paperclip-s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ module ClassMethods
# Extends the paperclips has_attached_file method
# It will use S3 Storage. The credentials will be read from the environment
def has_attached_file(name, options = {})
ActiveRecord::Base.logger.error {"\n\n\n#################################### Hello from S3 Gem"}
options[:storage] = :s3
options[:path] = "/:class-:attachment/:id/:style-:basename.:extension"
options[:bucket] = ENV["S3_BUCKET"]
options[:s3_credentials] = {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
options[:path] ||= "/:class-:attachment/:id/:style-:basename.:extension"
options[:bucket] ||= ENV["S3_BUCKET"]
options[:s3_credentials] ||= {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
}
super(name, options)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip-s3/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Paperclip
module S3
VERSION = "1.0.0rc1"
VERSION = "1.0.0"
end
end

0 comments on commit 5f6b68a

Please sign in to comment.