Class: Heirloom::Uploader::S3
- Inherits:
-
Object
- Object
- Heirloom::Uploader::S3
- Defined in:
- lib/heirloom/uploader/s3.rb
Instance Method Summary collapse
- #add_endpoint_attributes(args) ⇒ Object
-
#initialize(args) ⇒ S3
constructor
A new instance of S3.
- #upload_file(args) ⇒ Object
Constructor Details
#initialize(args) ⇒ S3
Returns a new instance of S3.
5 6 7 8 9 |
# File 'lib/heirloom/uploader/s3.rb', line 5 def initialize(args) @config = args[:config] @region = args[:region] @logger = args[:logger] end |
Instance Method Details
#add_endpoint_attributes(args) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/heirloom/uploader/s3.rb', line 33 def add_endpoint_attributes(args) bucket = args[:bucket] id = args[:id] name = args[:name] key_name = args[:key_name] domain = "heirloom_#{name}" key_folder = name endpoint = endpoints[@region] path = "#{bucket}/#{key_folder}/#{key_name}" end_point_attributes(path).each_pair do |key, value| add_endpoint_attribute domain, id, key, value end end |
#upload_file(args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/heirloom/uploader/s3.rb', line 11 def upload_file(args) bucket = args[:bucket] file = args[:file] id = args[:id] key_name = args[:key_name] key_folder = args[:key_folder] name = args[:name] public_readable = args[:public_readable] body = File.open file s3_bucket = s3.get_bucket bucket @logger.info "Uploading s3://#{bucket}/#{key_folder}/#{key_name}" s3_bucket.files.create :key => "#{key_folder}/#{key_name}", :body => body, :public => public_readable @logger.warn "File is readable by entire Internet." if public_readable body.close end |