Class: TranscodingMachine::Server::S3Storage
- Inherits:
-
Object
- Object
- TranscodingMachine::Server::S3Storage
- Defined in:
- lib/transcoding_machine/server/s3_storage.rb
Instance Method Summary collapse
- #get_file(key_name, destination_file_path, options) ⇒ Object
-
#initialize ⇒ S3Storage
constructor
A new instance of S3Storage.
- #put_file(source_file_path, destination_file_name, media_format, options) ⇒ Object
- #put_thumbnail_file(thumbnail_file, source_file_key_name, options) ⇒ Object
Constructor Details
#initialize ⇒ S3Storage
Returns a new instance of S3Storage.
6 7 8 |
# File 'lib/transcoding_machine/server/s3_storage.rb', line 6 def initialize @s3 = RightAws::S3.new(nil, nil, :server => 's3.amazonaws.com', :port => 80, :protocol => 'http') end |
Instance Method Details
#get_file(key_name, destination_file_path, options) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/transcoding_machine/server/s3_storage.rb', line 10 def get_file(key_name, destination_file_path, ) file = File.new(destination_file_path, File::CREAT|File::RDWR) rhdr = @s3.interface.get([:bucket], key_name) do |chunk| file.write(chunk) end file.close end |
#put_file(source_file_path, destination_file_name, media_format, options) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/transcoding_machine/server/s3_storage.rb', line 18 def put_file(source_file_path, destination_file_name, media_format, ) destination_key = RightAws::S3::Key.create(@s3.bucket([:bucket]), destination_file_name) s3_headers = { 'Content-Type' => media_format.mime_type, 'Content-Disposition' => "attachment; filename=#{File.basename(destination_file_name)}" } destination_key.put(File.new(source_file_path), 'public-read', s3_headers) FileUtils.rm(source_file_path) end |
#put_thumbnail_file(thumbnail_file, source_file_key_name, options) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/transcoding_machine/server/s3_storage.rb', line 28 def put_thumbnail_file(thumbnail_file, source_file_key_name, ) destination_key = RightAws::S3::Key.create(@s3.bucket([:bucket]), "#{source_file_key_name}.thumb.jpg") destination_key.put(thumbnail_file, 'public-read', 'Content-Type' => 'image/jpg') FileUtils.rm(thumbnail_file.path) destination_key.name end |