Method: Cloudlib::Entry.from_file

Defined in:
lib/cloudlib.rb

.from_file(path, filename = path, attributes = {'all_words' => []}) ⇒ Object

Creates and saves an entry from a file, using attributes supplied. Returns the entry.



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/cloudlib.rb', line 113

def self.from_file(path, filename=path, attributes={'all_words' => []})
  sha1 = Digest::SHA1.file(path).hexdigest
  ext  = File.extname(filename)
  name = "#{sha1}#{ext}"
  attributes['size'] = File.size(path).to_s
  attributes['date-added'] = Date.today.to_s
  entry = Entry.new(name, attributes)
  AWS::S3::S3Object.store(name, open(path), @@bucket)
  @@db.put_attributes(@@bucket, name, attributes, replace=true)
  return entry
end