Skip to content

Instantly share code, notes, and snippets.

@t11a
Created January 19, 2013 14:08
Show Gist options
  • Save t11a/4572838 to your computer and use it in GitHub Desktop.
Save t11a/4572838 to your computer and use it in GitHub Desktop.
require 'aws-sdk'
AWS.config(
:access_key_id => 'your_access_key_id',
:secret_access_key => 'your_secret_access_key',
:s3_endpoint => 's3-ap-northeast-1.amazonaws.com' # see http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
)
s3 = AWS::S3.new
bucket_name = 'your_bucket/path/to'
bucket = s3.buckets[bucket_name]
path_to = '/path/to'
upload_files = ['file1','file2']
uploaded_files = upload_files.map do |file|
file = path_to + "/" + file
basename = File.basename(file)
obj = bucket.objects[basename]
res = obj.write(:file => file, :acl => :private)
res.key
end
puts "S3 Upload Success:#{uploaded_files.to_s}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment