module Paperclip::Storage::Reduceds3

Public Class Methods

extended(base) click to toggle source
# 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