lib/paperclip-aws.rb in paperclip-aws-1.3.5 vs lib/paperclip-aws.rb in paperclip-aws-1.4.0

- old
+ new

@@ -13,11 +13,14 @@ rescue LoadError => e e.message << " (You may need to install the aws-sdk gem)" raise e end unless defined?(AWS) - base.instance_eval do + attr_accessor :s3_options + base.instance_eval do + + @s3_credentials = parse_credentials(@options.s3_credentials) @s3_permissions = set_permissions(@options.s3_permissions) @s3_protocol = @options.s3_protocol || Proc.new do |style, attachment| @@ -31,14 +34,22 @@ @s3_bucket = @options.bucket @s3_bucket = @s3_bucket.call(self) if @s3_bucket.is_a?(Proc) @s3_options = @options.s3_options || {} # setup Amazon Server Side encryption - @s3_sse = @s3_options[:sse] || false - # choose what storage class we use, 'standard' or 'reduced_redundancy' - @s3_storage_class = @s3_options[:storage_class] || :standard + @s3_options.reverse_merge!({ + :sse => false, + :storage_class => :standard, + :content_disposition => nil + }) + # @s3_sse = @s3_options[:sse] || false + # # choose what storage class we use, 'standard' or 'reduced_redundancy' + # @s3_storage_class = @s3_options[:storage_class] || :standard + # + # @s3_content_disposition = @s3_options[:content_disposition] || '' + @s3_endpoint = @s3_credentials[:endpoint] || 's3.amazonaws.com' @s3_host_alias = @options.s3_host_alias @s3_host_alias = @s3_host_alias.call(self) if @s3_host_alias.is_a?(Proc) @@ -136,14 +147,15 @@ @queued_for_write.each do |style, file| begin log("saving #{path(style)}") @s3.buckets[@s3_bucket].objects[path(style)].write( - file, + :file => file.path, :acl => @s3_permissions[:style.to_sym] || @s3_permissions[:default], - :storage_class => @s3_storage_class.to_sym, + :storage_class => @s3_options[:storage_class], :content_type => file.content_type, - :server_side_encryption => @s3_sse + :content_disposition => @s3_options[:content_disposition], + :server_side_encryption => @s3_options[:sse] ) rescue AWS::S3::Errors::NoSuchBucket => e create_bucket retry rescue AWS::Errors::Base => e