S3 flash upload is a rails plugin which allow user uploading a file to your S3 bucket directly, so you can save the cost of forwarding file to S3 in your app side.
Install
$ script/plugin install git://github.com/elcgit/s3-swf-upload-plugin.git
Usage
1. To use it, you should first execute the generator.
$ script/generate s3_swf_upload
2. configure config/amazon_s3.yml, you need put a crossdomain.xml in your bucket and make it public-read.
3. include s3_upload.js in your layouts:
< %= javascript_include_tag 's3_upload' %>
4. init s3_swf object:
< %= link_to_function 'Upload', 's3_swf.upload("prefix/")' %>
5. when you click upload, your file will be upload to http://bucket.s3.amazonasw.com/prefix/
This plugin has a new version available here: http://www.elctech.com/articles/updates-on-rails-s3-flash-upload-plugin
4 Comments
Is this easily modified to upload to private bucket?
All buckets and objects on S3 are individually access controlled, so you can upload anything anywhere (that you own…) and you just change the access to only be readable by the owner of the file only which would make it private. The way that the S3 POSTs work is that you generate a “policy file” which is basically just a config file of where you want the file uploaded to, what access it has, etc and then you encrypt it using your AWS secret key as a private key. Let me know if you need any help with it
Hi there,
Just a question about
< %= link_to_function 'Upload', 's3_swf.upload("prefix/")' %>Is there any server side verification of the upload prefix? Or can someone modify this client side to upload anywhere?
Hi, Eaden, I think it will upload to anywhere specified in client side at currently. Because file is uploaded to S3 directly, so we can’t verify it on server side.
we’ll think adding the prefix restriction in next version, thanks for your feedback.