Module: Paperclip::Storage::Reduceds3

Defined in:
lib/reduceds3.rb

Class Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/reduceds3.rb', line 26

def self.extended base
  base.extend(S3)
  base.class_eval do
    def flush_writes #:nodoc:
      @queued_for_write.each do |style, file|
        begin
          # FIX OLIVIER : we personnalize headers
          s3_headers = @s3_headers ? @s3_headers.dup : {}
          if @options[:styles][style][:s3_reduced]
            s3_headers['x-amz-storage-class'] = 'REDUCED_REDUNDANCY'
          end
          # puts "HEADERS: #{s3_headers.inspect}"
          log("saving #{path(style)}")
          AWS::S3::S3Object.store(path(style),
          file,
          bucket_name,
          {:content_type => instance_read(:content_type),
            :access => @s3_permissions,
          }.merge(s3_headers))
        rescue AWS::S3::NoSuchBucket => e
          create_bucket
          retry
        rescue AWS::S3::ResponseError => e
          raise
        end
      end
      @queued_for_write = {}
    end
  end
end