-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.rb
38 lines (30 loc) · 879 Bytes
/
s3.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require File.expand_path(File.dirname(__FILE__) + './ecto/config')
require 'securerandom'
bucket_name =ARGV[1]
file_name = ARGV[0]
#bucket_name &&
unless file_name
puts "Usage: upload_file.rb <FILE_NAME> <BUCKET_NAME>"
exit 1
end
unless bucket_name
bucket_name = SecureRandom.urlsafe_base64(8).downcase
end
# get an instance of the S3 interface using the default configuration
s3 = AWS::S3.new
# create a bucket
b = s3.buckets.create(bucket_name)
# upload a file
basename = File.basename(file_name)
o = b.objects[basename]
o.write(:file => file_name)
puts "Uploaded #{file_name} to:"
puts o.public_url
# generate a presigned URL
puts "\nUse this URL to download the file:"
puts o.url_for(:read)
puts "(press any key to delete the object)"
$stdin.getc
# o.delete #file delete
#b.delete - deletes bucket
b.delete! #.delete! - deletes all files then bucket