lib/paperclip-aws.rb in paperclip-aws-1.1.3 vs lib/paperclip-aws.rb in paperclip-aws-1.2.0

- old
+ new

@@ -20,11 +20,12 @@ @s3_bucket = @options[:s3_bucket] || @s3_credentials[:bucket] @s3_bucket = @s3_bucket.call(self) if @s3_bucket.is_a?(Proc) # setup permissions @s3_acl = @options[:s3_acl] || :public_read - + @s3_sse = @options[:s3_sse] + # choose what storage class we use, 'standard' or 'reduced_redundancy' @s3_storage_class = @options[:s3_storage_class] || :standard @s3_protocol = @options[:s3_protocol] || 'http' @s3_headers = @options[:s3_headers] || {} @@ -72,11 +73,18 @@ env = Object.const_defined?(:Rails) ? Rails.env : nil (creds[env] || creds).symbolize_keys end def exists?(style = default_style) - @s3.buckets[@s3_bucket].objects[path(style)].exists? + if path(style).nil? || path(style).to_s.strip == "" + return false + end + begin + return @s3.buckets[@s3_bucket].objects[path(style)].exists? + rescue AWS::S3::Errors::NoSuchKey + return false + end end def choose_protocol(options={}) if options[:protocol].present? return options[:protocol].to_s @@ -105,21 +113,22 @@ def flush_writes #:nodoc: @queued_for_write.each do |style, file| begin log("saving #{path(style)}") - + @s3.buckets[@s3_bucket].objects[path(style)].write( file, :acl => @s3_acl, :storage_class => @s3_storage_class, - :content_type => file.content_type + :content_type => file.content_type, + :server_side_encryption => @s3_sse ) rescue AWS::S3::Errors::NoSuchBucket => e create_bucket retry - rescue AWS::S3::Errors::Base => e + rescue AWS::Errors::Base => e raise end end @queued_for_write = {} end @@ -127,11 +136,11 @@ def flush_deletes #:nodoc: @queued_for_delete.each do |path| begin log("deleting #{path}") @s3.buckets[@s3_bucket].objects[path].delete - rescue AWS::S3::Base => e + rescue AWS::Errors::Base => e raise end end @queued_for_delete = [] end @@ -150,6 +159,6 @@ end private :find_credentials end end -end \ No newline at end of file +end