Upload files to s3 with flash, including progress bars, in your Rails app. Configuration requires an s3 key and secret only.
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
config.flash_s3.bucket = 'mybucketname'
config.flash_s3.s3_access_key_id = "myaccesskey"
config.flash_s3.s3_secret_access_key = "mysecretaccesskey"
add_column :<your_model_name_pluralized>, :<your_attachment_name>_s3_key :string
e.g.
add_column :videos, :media_s3_key, :string
Let's say it's called Video
.
has_attached_s3_file :media
Substitute your upload name for media
.
//= require jquery.ui.all
//= require jquery.flashS3
/*
*= require jquery.flashS3
*/
<%= flash_s3_uploader @video, :media, post_upload_callback_url %>
= flash_s3_uploader @video, :media, post_upload_callback_url
Note: You must use the url and not the path for your post callback hook.
def create
@video = Video.new(params[:video])
@video.save!
head :ok
end
Or 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.
- 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 ;)
- 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