Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

S3 upload client for Ruby (See related posts)

Uses Marcel Molina's AWS::S3 gem.. gem install aws-s3

#!/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!"

Comments on this post

jrobertson posts on Apr 26, 2008 at 07:17
Is there a new which replaces aws-s3, I couldn't get it to install?

Here's the gem install aws-s3 message output:

Bulk updating Gem source index for: http://gems.rubyforge.org
ERROR: While executing gem ... (Gem::GemNotFoundException)
Could not find aws-s3 (> 0) in any repository
jrobertson posts on Apr 26, 2008 at 07:57
Ignore my previous comment, I upgraded to Ubuntu 8.04 and noticed that some of the other Gems aren't installing either.
The aws-s3 gem installs fine on my other Ubuntu 7.10 box!

You need to create an account or log in to post comments to this site.


Click here to browse all 4834 code snippets

Related Posts