Post by Peter Cooper on November 30th, 2006
Simple File Upload to Amazon S3 From Ruby

- Rails File Uploading 101
- No True “mod_ruby” Is Damaging Ruby’s Viability On The Web
- SwitchPipe: My New Rapid and Easy Way To Deploy Web Apps


There's more about Amazon S3 and Marcel Molina's hot new library coming as the first day of the Ruby Advent Calendar (this Friday!), so I don't want to say too much about it yet. For anyone already enjoying this library, however, I put together a scrappy program that lets me copy files up to S3 from the command line easily:
#!/usr/bin/env ruby require 'rubygems' require 'aws/s3' local_file = ARGV[0] bucket = ARGV[1] mime_type = ARGV[2] || "application/octet-stream" AWS::S3::Base.establish_connection!( :access_key_id => 'REPLACE_ME', :secret_access_key => 'REPLACE_ME' ) base_name = File.basename(local_file) puts "Uploading #{local_file} as '#{base_name}' to '#{bucket}'" AWS::S3::S3Object.store( base_name, File.open(local_file), bucket, :content_type => mime_type ) puts "Uploaded!"
Just name it s3cp (or similar), chmod it, and then you can do stuff like:
s3cp ~/somefile.whatever bucket

Click here to add on del.icio.us









November 30th, 2006 at 4:35 pm
S3 tools are definitely getting more interesting. This one is nice and simple.
I'm still hoping for one that's compatible with Jungle Disk's encryption.