Return to Snippet

Revision: 1961
at November 30, 2006 10:27 by sudarkoff


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

Initial URL
http://www.rubyinside.com/simple-file-upload-to-amazon-s3-from-ruby-313.html

Initial Description
Just name it s3cp (or similar), chmod it, and then you can do stuff like:

s3cp ~/somefile.whatever bucket

Initial Title
Simple File Upload to Amazon S3 From Ruby

Initial Tags
ruby

Initial Language
Ruby