Over a million developers have joined DZone.

S3 Upload Client For Ruby

·
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!"
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}