Class: TranscodingMachine::Server::S3Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/transcoding_machine/server/s3_storage.rb

Instance Method Summary collapse

Constructor Details

#initializeS3Storage

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, options)
  file = File.new(destination_file_path, File::CREAT|File::RDWR)
  rhdr = @s3.interface.get(options[: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, options)
  destination_key = RightAws::S3::Key.create(@s3.bucket(options[: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, options)
  destination_key = RightAws::S3::Key.create(@s3.bucket(options[: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