Skip to content

Instantly share code, notes, and snippets.

@pierrevalade
Created July 1, 2009 09:34
Show Gist options
  • Save pierrevalade/138705 to your computer and use it in GitHub Desktop.
Save pierrevalade/138705 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'right_aws'
i = 1
path = '/Users/pierre/Desktop/items/pictures/**/*'
s3 = RightAws::S3.new(access_key, secret_key)
s3_bucket = s3.bucket('twistip', false, 'public-read')
headers = {'Content-type' => 'image/jpeg', 'Expires' => "Thu, 01 Jul 2019 08:37:04 GMT", 'Cache-Control' => 'public, max-age=315360000'}
Dir.glob(path).each do |f|
next if File.directory?(f)
p = "items/pictures/#{f[path.length, f.length]}"
key = s3_bucket.key(p)
unless key.exists?
puts("#{i} - saving #{p} ...")
key.data = File.read(f)
key.put(nil, 'public-read', headers)
puts("#{i} - saved #{p}")
else
puts("#{i} - skipped #{p}")
end
i += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment