· 7 years ago · Apr 12, 2018, 09:36 PM
1require 'rubygems'
2require 'right_aws'
3
4i = 1
5path = '/Users/pierre/Desktop/items/pictures/**/*'
6
7s3 = RightAws::S3.new(access_key, secret_key)
8s3_bucket = s3.bucket('twistip', false, 'public-read')
9
10headers = {'Content-type' => 'image/jpeg', 'Expires' => "Thu, 01 Jul 2019 08:37:04 GMT", 'Cache-Control' => 'public, max-age=315360000'}
11
12Dir.glob(path).each do |f|
13 next if File.directory?(f)
14 p = "items/pictures/#{f[path.length, f.length]}"
15 key = s3_bucket.key(p)
16
17 unless key.exists?
18 puts("#{i} - saving #{p} ...")
19
20 key.data = File.read(f)
21 key.put(nil, 'public-read', headers)
22
23 puts("#{i} - saved #{p}")
24 else
25 puts("#{i} - skipped #{p}")
26 end
27
28 i += 1
29end