How to upload binary data to Amazon S3 from a Rails app? - ruby-on-rails

I am using the gems Paperclip & aws-s3 to upload images to Amazon S3 from my Rails app. This all works fine. What I am now trying to do is upload some binary data to S3 and return the URL. How can I do that?

You'll find a tutorial with examples here:
http://amazon.rubyforge.org
Look at the S3Object.store method.
EDIT:
You should now use the official Amazon SDK:
http://aws.amazon.com/sdkforruby/

Related

Uploading image from PhoneGap to Carrierwave / Rails 3?

I'm trying to figure out the best way to upload a camera image from a PhoneGap app to a Rails 3 app that has Carrierwave on it. My thoughts so far:
Option 1) Use phonegap filetransfer functionality to upload to a temp folder on S3 then assign the URL to the remote_avatar_url for my carrierwave field. Then carrierwave does all the work for me in terms of grabbing the image, resizing, cropping, etc. Carrierwave will then send the files back over to S3 where they will be stored in the right places.
Option 2) Use phonegap filetransfer functionality to upload directly to my rails server then let carrierwave do the work from here. This seems more efficient, but I don't know how to assign an image that was posted to a rails api controller to Carrierwave so that it can do its thing. Any ideas assuming this is the best way to handle?
Thanks!
You can send the image as Base64/encode and than parse it on the CarrierWave side. Take a look at http://ograycoding.wordpress.com/2012/07/03/api-upload-with-carrierwave/

How to create multipart upload to s3 (Rails)

is there any gem/ plugin or any refference to create multipart upload to s3 in Ruby on Rails?
ref : http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingRESTAPImpUpload.html
I wish to create upload very large file and need to seperate it.
I think you can try this plugin for uploading files directly to the amazon s3. I am going to use it in my the current project.
Carrierwave Direct

Carrierwave multi file (photo) upload

I have Ruby on Rails app and I use Carrierwave for uploading my images, but I need upload more than one image at a time. I find some jQuery plugins(uploadify, image-uplad) but I don't know how implement it to my app. I don't need a huge app/engine for it.
Check it : http://lucapette.com/rails/multiple-files-upload-with-carrierwave-and-nested_form/
Uploading multiple files at once to Rails app with Carrierwave (HTML5)

file upload progress bar with paperclip on heroku

I need to show a progress bar for file uploads and i have no idea. Any help will be appreciated.
Application is on Heroku and files are on S3
I'd use jQuery file upload which doesn't require flash, only javascript and is compatible with all browser (including IE6): https://github.com/blueimp/jQuery-File-Upload
I wrote the tutorial in the wiki and made a sample app here: https://github.com/apneadiving/Pic-upload---Crop-in-Ajax
Using both jQuery File Upload and Uploadify (on in each branch)
I have written a blog post about using rails 4 with paperclip and uploadify.
http://vignesh.info/blog/rails-4-uploadify-paperclip/
Paperclip already supports aws api and files can be stored on S3. If you have plans of using dropbox take a look at this gem https://github.com/janko-m/paperclip-dropbox

Uploading to s3, using s3 servers

Does anyone have any sample code (preferrably in rails) that uploads to s3, using s3's servers.
Again, uploading directly to s3, where the actual upload/streaming is also preformed on amazon's servers.
Requirements:
Plupload, jQuery
Idea:
Authorize Upload via your app (sign it on server-side)
Use the signed request to upload the file to S3
Notify your app that the upload is done
Check whether S3 has received the file
I posted the code as a gist at https://gist.github.com/759939, it misses commments and you might run into some issues due to missing methods (had to rip it from our codebase).
stored_file.rb contains a model for your DB. Has many of paperclips helper methods inlined (which we used before we switched to direct upload to S3).
I hope you can use it as a sample to get your stuff running.
If you are using Rails 3, please check out my sample projects:
Sample project using Rails 3, Flash and MooTools-based FancyUploader to upload directly to S3: https://github.com/iwasrobbed/Rails3-S3-Uploader-FancyUploader
Sample project using Rails 3, Flash/Silverlight/GoogleGears/BrowserPlus and jQuery-based Plupload to upload directly to S3: https://github.com/iwasrobbed/Rails3-S3-Uploader-Plupload
To simply copy files, this is easy to use:
Smart Copy Script into S3
Amazon wrote a Ruby library for the S3 REST API. I haven't used it yet.
http://amazon.rubyforge.org/

Resources