FlashS3Rails
Upload files to s3 with flash, including progress bars, in your Rails app. Configuration requires an s3 key and secret only.
Installation
Add this line to your application's Gemfile:
gem 'flash_s3_rails', '~> 0.0.1.beta1', :require => 'flash_s3'
And then execute:
$ bundle
Or install it yourself as:
$ gem install flash_s3_rails --pre
Usage
In application.rb or <environment>.rb or an initializer
config.flash_s3.bucket = 'mybucketname'
config.flash_s3.s3_access_key_id = "myaccesskey"
config.flash_s3.s3_secret_access_key = "mysecretaccesskey"In a migration
add_column :<your_model_name_pluralized>, :<your_attachment_name>_s3_key :stringe.g.
add_column :videos, :media_s3_key, :stringIn the Model
Let's say it's called Video.
has_attached_s3_file :mediaSubstitute your upload name for media.
In your app/assets/javascripts/application.js
//= require jquery.ui.all
//= require jquery.flashS3In your app/assets/stylesheets/application.css
/*
*= require jquery.flashS3
*/In the View
Erb
<%= flash_s3_uploader @video, :media, post_upload_callback_url %>Haml
= flash_s3_uploader @video, :media, post_upload_callback_urlNote: You must use the url and not the path for your post callback hook.
In your Controller (post upload callback action)
def create
@video = Video.new(params[:video])
@video.save!
head :ok
endOr whatever ;) The point is to new, create, update_attributes, etc, your Model instance with the attachment_s3_key column and has_attached_s3_file and save it! Your s3_key will be saved automagically.
Upcoming
- Additional custom post callback params
- More configurable, e.g. max file size, file type(s) accepted
- Drop jquery-ui dependency and implement a simple css progress bar
- Make the green box a little less ugly ;)
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request