From 8f7f29fc109c0f1c9189ca64e7d412e8f96c761d Mon Sep 17 00:00:00 2001 From: Airton Sampaio de Sobral Date: Sat, 21 Nov 2015 17:10:30 -0300 Subject: [PATCH 01/30] Fix condition to include Schema, using 'ActiveRecord::Base' instead of 'ActiveRecord' solo --- lib/paperclip/glue.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paperclip/glue.rb b/lib/paperclip/glue.rb index 2d14c627a..c8d9e89a3 100644 --- a/lib/paperclip/glue.rb +++ b/lib/paperclip/glue.rb @@ -8,7 +8,7 @@ def self.included(base) base.extend ClassMethods base.send :include, Callbacks base.send :include, Validators - base.send :include, Schema if defined? ActiveRecord + base.send :include, Schema if defined? ActiveRecord::Base locale_path = Dir.glob(File.dirname(__FILE__) + "/locales/*.{rb,yml}") I18n.load_path += locale_path unless I18n.load_path.include?(locale_path) From 134b7b49eee56914742a180f5be2de4a384e0937 Mon Sep 17 00:00:00 2001 From: Erkki Eilonen Date: Mon, 30 Nov 2015 22:26:29 +0200 Subject: [PATCH 02/30] fix S3 adapter runtime constant definition not being thread-safe --- lib/paperclip/storage/s3.rb | 32 ++++++++++++++++--------------- spec/paperclip/storage/s3_spec.rb | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index ae91cdae7..c54829bcd 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -113,21 +113,23 @@ module Storage module S3 def self.extended base - unless defined?(AWS_CLASS) - begin - require 'aws-sdk' - const_set('AWS_CLASS', defined?(::Aws) ? ::Aws : ::AWS) - const_set('AWS_BASE_ERROR', - defined?(::Aws) ? Aws::Errors::ServiceError : AWS::Errors::Base) - const_set('DEFAULT_PERMISSION', - defined?(::AWS) ? :public_read : :'public-read') - - rescue LoadError => e - e.message << " (You may need to install the aws-sdk gem)" - raise e - end - if Gem::Version.new(AWS_CLASS::VERSION) >= Gem::Version.new(2) && Gem::Version.new(AWS_CLASS::VERSION) <= Gem::Version.new("2.0.33") - raise LoadError, "paperclip does not support aws-sdk versions 2.0.0 - 2.0.33. Please upgrade aws-sdk to a newer version." + Thread.exclusive do + unless defined?(AWS_CLASS) + begin + require 'aws-sdk' + const_set('AWS_CLASS', defined?(::Aws) ? ::Aws : ::AWS) + const_set('AWS_BASE_ERROR', + defined?(::Aws) ? Aws::Errors::ServiceError : AWS::Errors::Base) + const_set('DEFAULT_PERMISSION', + defined?(::AWS) ? :public_read : :'public-read') + + rescue LoadError => e + e.message << " (You may need to install the aws-sdk gem)" + raise e + end + if Gem::Version.new(AWS_CLASS::VERSION) >= Gem::Version.new(2) && Gem::Version.new(AWS_CLASS::VERSION) <= Gem::Version.new("2.0.33") + raise LoadError, "paperclip does not support aws-sdk versions 2.0.0 - 2.0.33. Please upgrade aws-sdk to a newer version." + end end end diff --git a/spec/paperclip/storage/s3_spec.rb b/spec/paperclip/storage/s3_spec.rb index c361bfc35..78ba72791 100644 --- a/spec/paperclip/storage/s3_spec.rb +++ b/spec/paperclip/storage/s3_spec.rb @@ -14,6 +14,21 @@ def aws2_add_region defined?(::Aws) ? { s3_region: 'us-east-1' } : {} end + context 'multithreaded initialization' do + before do + end + it "should not fail on missing constants" do + 10.times.map do |i| + Thread.new do + ActiveRecord::Base.connection_pool.with_connection do |_| + rebuild_model (aws2_add_region).merge storage: :s3 + Dummy.new.avatar + end + end + end.map{|t| t.join} + end + end + context "Parsing S3 credentials" do before do @proxy_settings = {host: "127.0.0.1", port: 8888, user: "foo", password: "bar"} From 11e4a6318161278aff7d2703c92f1cfc04a07c6f Mon Sep 17 00:00:00 2001 From: Erkki Eilonen Date: Mon, 30 Nov 2015 22:39:40 +0200 Subject: [PATCH 03/30] remove unused block --- spec/paperclip/storage/s3_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/paperclip/storage/s3_spec.rb b/spec/paperclip/storage/s3_spec.rb index 78ba72791..6bf158405 100644 --- a/spec/paperclip/storage/s3_spec.rb +++ b/spec/paperclip/storage/s3_spec.rb @@ -15,8 +15,6 @@ def aws2_add_region end context 'multithreaded initialization' do - before do - end it "should not fail on missing constants" do 10.times.map do |i| Thread.new do From 81423af2f73352cd2fd0fd24e9749d063f191be5 Mon Sep 17 00:00:00 2001 From: Erkki Eilonen Date: Mon, 30 Nov 2015 22:40:07 +0200 Subject: [PATCH 04/30] double quotes as per hound feedback --- spec/paperclip/storage/s3_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/paperclip/storage/s3_spec.rb b/spec/paperclip/storage/s3_spec.rb index 6bf158405..e5bf6856d 100644 --- a/spec/paperclip/storage/s3_spec.rb +++ b/spec/paperclip/storage/s3_spec.rb @@ -14,7 +14,7 @@ def aws2_add_region defined?(::Aws) ? { s3_region: 'us-east-1' } : {} end - context 'multithreaded initialization' do + context "multithreaded initialization" do it "should not fail on missing constants" do 10.times.map do |i| Thread.new do From 0167bf29394695aa59ce615e18656e0c58392421 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Tue, 10 Nov 2015 12:22:09 +0000 Subject: [PATCH 05/30] Remove duplication by reusing existing method. --- lib/paperclip/storage/s3.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index 50caf1b29..9b10e2829 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -379,11 +379,9 @@ def flush_writes #:nodoc: retries = 0 begin log("saving #{path(style)}") - acl = @s3_permissions[style] || @s3_permissions[:default] - acl = acl.call(self, style) if acl.respond_to?(:call) write_options = { :content_type => file.content_type, - :acl => acl + :acl => s3_permissions(style) } # add storage class for this style if defined From 0b73776db5812ffd29ba729117b17c36271e1f05 Mon Sep 17 00:00:00 2001 From: Tute Costa Date: Tue, 8 Sep 2015 21:46:42 -0400 Subject: [PATCH 06/30] Remove locales from main repository Extract another repository only concerned with locales: https://github.com/thoughtbot/paperclip-i18n A user of paperclip might choose to add `paperclip-i18n` as a dependency for their application, or copy over the related locale file into their project. This is a first step in splitting some parts of the codebase into other projects. Simple and relevant contributions like new translations might get lost in the shuffle of dozens of PRs awaiting for approval, that take time to review and merge. Locales are a simple enough problem to be handled in an external repository, where tests for consistency across translations run in less than a second, and PRs can almost trivially be merged in. --- README.md | 7 +++++++ lib/paperclip/locales/de.yml | 18 ------------------ lib/paperclip/locales/es.yml | 18 ------------------ lib/paperclip/locales/ja.yml | 18 ------------------ lib/paperclip/locales/pt-BR.yml | 18 ------------------ lib/paperclip/locales/tr.yml | 18 ------------------ lib/paperclip/locales/zh-CN.yml | 18 ------------------ lib/paperclip/locales/zh-HK.yml | 18 ------------------ lib/paperclip/locales/zh-TW.yml | 18 ------------------ 9 files changed, 7 insertions(+), 144 deletions(-) delete mode 100644 lib/paperclip/locales/de.yml delete mode 100644 lib/paperclip/locales/es.yml delete mode 100644 lib/paperclip/locales/ja.yml delete mode 100644 lib/paperclip/locales/pt-BR.yml delete mode 100644 lib/paperclip/locales/tr.yml delete mode 100644 lib/paperclip/locales/zh-CN.yml delete mode 100644 lib/paperclip/locales/zh-HK.yml delete mode 100644 lib/paperclip/locales/zh-TW.yml diff --git a/README.md b/README.md index 4191dd4a9..60eec448f 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Paperclip - [Deleting an Attachment](#deleting-an-attachment) - [Usage](#usage) - [Validations](#validations) +- [Internationalization (I18n)](#internationalization-i18n) - [Security Validations](#security-validations) - [Defaults](#defaults) - [Migrations](#migrations-1) @@ -400,6 +401,12 @@ inferred content_type, regardless of the actual contents of the file. --- +Internationalization (I18n) +--------------------------- + +For using or adding locale files in different languages, check the project +https://github.com/thoughtbot/paperclip-i18n. + Security Validations ==================== diff --git a/lib/paperclip/locales/de.yml b/lib/paperclip/locales/de.yml deleted file mode 100644 index 028f7c6eb..000000000 --- a/lib/paperclip/locales/de.yml +++ /dev/null @@ -1,18 +0,0 @@ -de: - errors: - messages: - in_between: "muss zwischen %{min} und %{max} sein" - spoofed_media_type: "trägt eine Dateiendung, die nicht mit dem Inhalt der Datei übereinstimmt" - - number: - human: - storage_units: - format: "%n %u" - units: - byte: - one: "Byte" - other: "Bytes" - kb: "KB" - mb: "MB" - gb: "GB" - tb: "TB" diff --git a/lib/paperclip/locales/es.yml b/lib/paperclip/locales/es.yml deleted file mode 100644 index 53d04dfc2..000000000 --- a/lib/paperclip/locales/es.yml +++ /dev/null @@ -1,18 +0,0 @@ -es: - errors: - messages: - in_between: "debe estar entre %{min} y %{max}" - spoofed_media_type: "tiene una extensión que no coincide con su contenido" - - number: - human: - storage_units: - format: "%n %u" - units: - byte: - one: "Byte" - other: "Bytes" - kb: "KB" - mb: "MB" - gb: "GB" - tb: "TB" diff --git a/lib/paperclip/locales/ja.yml b/lib/paperclip/locales/ja.yml deleted file mode 100644 index fb9dd9941..000000000 --- a/lib/paperclip/locales/ja.yml +++ /dev/null @@ -1,18 +0,0 @@ -ja: - errors: - messages: - in_between: "の容量は%{min}以上%{max}以下にしてください。" - spoofed_media_type: "の拡張子と内容が一致していません。" - - number: - human: - storage_units: - format: "%n %u" - units: - byte: - one: "Byte" - other: "Bytes" - kb: "KB" - mb: "MB" - gb: "GB" - tb: "TB" diff --git a/lib/paperclip/locales/pt-BR.yml b/lib/paperclip/locales/pt-BR.yml deleted file mode 100644 index 12b257d1c..000000000 --- a/lib/paperclip/locales/pt-BR.yml +++ /dev/null @@ -1,18 +0,0 @@ -pt-BR: - errors: - messages: - in_between: "deve ter entre %{min} e %{max}" - spoofed_media_type: "tem uma extensão que não corresponde ao seu conteúdo" - - number: - human: - storage_units: - format: "%n %u" - units: - byte: - one: "Byte" - other: "Bytes" - kb: "KB" - mb: "MB" - gb: "GB" - tb: "TB" diff --git a/lib/paperclip/locales/tr.yml b/lib/paperclip/locales/tr.yml deleted file mode 100644 index 306423bc4..000000000 --- a/lib/paperclip/locales/tr.yml +++ /dev/null @@ -1,18 +0,0 @@ -tr: - errors: - messages: - in_between: "%{min} ile %{max} arasında olmalıdır" - spoofed_media_type: "olmaması gerektiği raporlanan içerik bulunuyor" - - number: - human: - storage_units: - format: "%n %u" - units: - byte: - one: "Bayt" - other: "Bayt" - kb: "KB" - mb: "MB" - gb: "GB" - tb: "TB" diff --git a/lib/paperclip/locales/zh-CN.yml b/lib/paperclip/locales/zh-CN.yml deleted file mode 100644 index 29a8ddeb7..000000000 --- a/lib/paperclip/locales/zh-CN.yml +++ /dev/null @@ -1,18 +0,0 @@ -zh-CN: - errors: - messages: - in_between: "文件大小必须介于 %{min} 到 %{max} 之间" - spoofed_media_type: "扩展名与内容类型不符" - - number: - human: - storage_units: - format: "%n %u" - units: - byte: - one: "Byte" - other: "Bytes" - kb: "KB" - mb: "MB" - gb: "GB" - tb: "TB" diff --git a/lib/paperclip/locales/zh-HK.yml b/lib/paperclip/locales/zh-HK.yml deleted file mode 100644 index 65cbbc807..000000000 --- a/lib/paperclip/locales/zh-HK.yml +++ /dev/null @@ -1,18 +0,0 @@ -zh-HK: - errors: - messages: - in_between: "必須介於%{min}到%{max}之間" - spoofed_media_type: "副檔名與內容類型不匹配" - - number: - human: - storage_units: - format: "%n %u" - units: - byte: - one: "Byte" - other: "Bytes" - kb: "KB" - mb: "MB" - gb: "GB" - tb: "TB" diff --git a/lib/paperclip/locales/zh-TW.yml b/lib/paperclip/locales/zh-TW.yml deleted file mode 100644 index dc6819cbc..000000000 --- a/lib/paperclip/locales/zh-TW.yml +++ /dev/null @@ -1,18 +0,0 @@ -zh-TW: - errors: - messages: - in_between: "檔案大小必須介於 %{min} 到 %{max} 之間" - spoofed_media_type: "副檔名與內容類型不符" - - number: - human: - storage_units: - format: "%n %u" - units: - byte: - one: "Byte" - other: "Bytes" - kb: "KB" - mb: "MB" - gb: "GB" - tb: "TB" From a4e14fb5f6faab7d0f427b54750ec3ded19a8a51 Mon Sep 17 00:00:00 2001 From: Tute Costa Date: Tue, 22 Dec 2015 19:17:31 -0300 Subject: [PATCH 07/30] Removes Rails 3.2 and 4.1 support In preparation for Rails 5, which, when it is released, will make Rails 3.2 and 4.1 unsupported. See: * http://weblog.rubyonrails.org/2015/12/18/Rails-5-0-beta1/ * https://github.com/thoughtbot/paperclip/issues/2049 --- .travis.yml | 6 ------ Appraisals | 30 ------------------------------ gemfiles/3.2.awsv1.gemfile | 17 ----------------- gemfiles/3.2.awsv2.0.gemfile | 17 ----------------- gemfiles/3.2.awsv2.1.gemfile | 17 ----------------- gemfiles/4.1.awsv1.gemfile | 17 ----------------- gemfiles/4.1.awsv2.0.gemfile | 17 ----------------- gemfiles/4.1.awsv2.1.gemfile | 17 ----------------- 8 files changed, 138 deletions(-) delete mode 100644 gemfiles/3.2.awsv1.gemfile delete mode 100644 gemfiles/3.2.awsv2.0.gemfile delete mode 100644 gemfiles/3.2.awsv2.1.gemfile delete mode 100644 gemfiles/4.1.awsv1.gemfile delete mode 100644 gemfiles/4.1.awsv2.0.gemfile delete mode 100644 gemfiles/4.1.awsv2.1.gemfile diff --git a/.travis.yml b/.travis.yml index 52e1d3436..93ebe8f9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,14 +6,8 @@ rvm: script: "bundle exec rake clean spec cucumber" gemfile: - - gemfiles/3.2.awsv2.1.gemfile - - gemfiles/4.1.awsv2.1.gemfile - gemfiles/4.2.awsv2.1.gemfile - - gemfiles/3.2.awsv2.0.gemfile - - gemfiles/4.1.awsv2.0.gemfile - gemfiles/4.2.awsv2.0.gemfile - - gemfiles/3.2.awsv1.gemfile - - gemfiles/4.1.awsv1.gemfile - gemfiles/4.2.awsv1.gemfile sudo: false diff --git a/Appraisals b/Appraisals index 240977dd6..9e984628c 100644 --- a/Appraisals +++ b/Appraisals @@ -1,43 +1,13 @@ -appraise "3.2.awsv2.1" do - gem "rails", "~> 3.2.0" - gem "aws-sdk", "~> 2.1.0" -end - -appraise "4.1.awsv2.1" do - gem "rails", "~> 4.1.0" - gem "aws-sdk", "~> 2.1.0" -end - appraise "4.2.awsv2.1" do gem "rails", "~> 4.2.0" gem "aws-sdk", "~> 2.1.0" end -appraise "3.2.awsv2.0" do - gem "rails", "~> 3.2.0" - gem "aws-sdk", "~> 2.0.0" -end - -appraise "4.1.awsv2.0" do - gem "rails", "~> 4.1.0" - gem "aws-sdk", "~> 2.0.0" -end - appraise "4.2.awsv2.0" do gem "rails", "~> 4.2.0" gem "aws-sdk", "~> 2.0.0" end -appraise "3.2.awsv1" do - gem "rails", "~> 3.2.0" - gem "aws-sdk", "~> 1.5" -end - -appraise "4.1.awsv1" do - gem "rails", "~> 4.1.0" - gem "aws-sdk", "~> 1.5" -end - appraise "4.2.awsv1" do gem "rails", "~> 4.2.0" gem "aws-sdk", "~> 1.5" diff --git a/gemfiles/3.2.awsv1.gemfile b/gemfiles/3.2.awsv1.gemfile deleted file mode 100644 index a40423302..000000000 --- a/gemfiles/3.2.awsv1.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "sqlite3", "~> 1.3.8", platforms: :ruby -gem "pry" -gem "rails", "~> 3.2.0" -gem "aws-sdk", "~> 1.5" - -group :development, :test do - gem "activerecord-import" - gem "mime-types", "~> 1.16" - gem "builder" - gem "rubocop", :require => false -end - -gemspec path: "../" diff --git a/gemfiles/3.2.awsv2.0.gemfile b/gemfiles/3.2.awsv2.0.gemfile deleted file mode 100644 index 8c7cd14a8..000000000 --- a/gemfiles/3.2.awsv2.0.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "sqlite3", "~> 1.3.8", platforms: :ruby -gem "pry" -gem "rails", "~> 3.2.0" -gem "aws-sdk", "~> 2.0.0" - -group :development, :test do - gem "activerecord-import" - gem "mime-types", "~> 1.16" - gem "builder" - gem "rubocop", :require => false -end - -gemspec path: "../" diff --git a/gemfiles/3.2.awsv2.1.gemfile b/gemfiles/3.2.awsv2.1.gemfile deleted file mode 100644 index 1b586574c..000000000 --- a/gemfiles/3.2.awsv2.1.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "sqlite3", "~> 1.3.8", platforms: :ruby -gem "pry" -gem "rails", "~> 3.2.0" -gem "aws-sdk", "~> 2.1.0" - -group :development, :test do - gem "activerecord-import" - gem "mime-types", "~> 1.16" - gem "builder" - gem "rubocop", :require => false -end - -gemspec path: "../" diff --git a/gemfiles/4.1.awsv1.gemfile b/gemfiles/4.1.awsv1.gemfile deleted file mode 100644 index 278659d4b..000000000 --- a/gemfiles/4.1.awsv1.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "sqlite3", "~> 1.3.8", platforms: :ruby -gem "pry" -gem "rails", "~> 4.1.0" -gem "aws-sdk", "~> 1.5" - -group :development, :test do - gem "activerecord-import" - gem "mime-types", "~> 1.16" - gem "builder" - gem "rubocop", :require => false -end - -gemspec path: "../" diff --git a/gemfiles/4.1.awsv2.0.gemfile b/gemfiles/4.1.awsv2.0.gemfile deleted file mode 100644 index 7295e2937..000000000 --- a/gemfiles/4.1.awsv2.0.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "sqlite3", "~> 1.3.8", platforms: :ruby -gem "pry" -gem "rails", "~> 4.1.0" -gem "aws-sdk", "~> 2.0.0" - -group :development, :test do - gem "activerecord-import" - gem "mime-types", "~> 1.16" - gem "builder" - gem "rubocop", :require => false -end - -gemspec path: "../" diff --git a/gemfiles/4.1.awsv2.1.gemfile b/gemfiles/4.1.awsv2.1.gemfile deleted file mode 100644 index 9ab82b0ca..000000000 --- a/gemfiles/4.1.awsv2.1.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "sqlite3", "~> 1.3.8", platforms: :ruby -gem "pry" -gem "rails", "~> 4.1.0" -gem "aws-sdk", "~> 2.1.0" - -group :development, :test do - gem "activerecord-import" - gem "mime-types", "~> 1.16" - gem "builder" - gem "rubocop", :require => false -end - -gemspec path: "../" From d570f1e4bbd1bee487cc88c981f20918abe47c29 Mon Sep 17 00:00:00 2001 From: Tute Costa Date: Tue, 22 Dec 2015 19:49:18 -0300 Subject: [PATCH 08/30] Remove AWS v1 support TODO: Simpify lib/paperclip/storage/s3.rb See: * https://github.com/thoughtbot/paperclip/issues/2049 --- .travis.yml | 1 - Appraisals | 5 ----- README.md | 6 +----- gemfiles/4.2.awsv1.gemfile | 17 ----------------- 4 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 gemfiles/4.2.awsv1.gemfile diff --git a/.travis.yml b/.travis.yml index 93ebe8f9c..17568d652 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ script: "bundle exec rake clean spec cucumber" gemfile: - gemfiles/4.2.awsv2.1.gemfile - gemfiles/4.2.awsv2.0.gemfile - - gemfiles/4.2.awsv1.gemfile sudo: false cache: bundler diff --git a/Appraisals b/Appraisals index 9e984628c..45342b53d 100644 --- a/Appraisals +++ b/Appraisals @@ -7,8 +7,3 @@ appraise "4.2.awsv2.0" do gem "rails", "~> 4.2.0" gem "aws-sdk", "~> 2.0.0" end - -appraise "4.2.awsv1" do - gem "rails", "~> 4.2.0" - gem "aws-sdk", "~> 1.5" -end diff --git a/README.md b/README.md index 60eec448f..97a6e40ce 100644 --- a/README.md +++ b/README.md @@ -561,7 +561,7 @@ Storage Paperclip ships with 3 storage adapters: * File Storage -* S3 Storage (via `aws-sdk` or `aws-sdk-v1`) +* S3 Storage (via `aws-sdk`) * Fog Storage If you would like to use Paperclip with another storage, you can install these @@ -591,10 +591,6 @@ the `aws-sdk` gem in your Gemfile: ```ruby gem 'aws-sdk', '>= 2.0.0' # If using paperclip `master` (upcoming v5.0) ``` -or -```ruby -gem 'aws-sdk-v1' # If using paperclip <= v4.3.1 -``` And then you can specify using S3 from `has_attached_file`. You can find more information about configuring and using S3 storage in diff --git a/gemfiles/4.2.awsv1.gemfile b/gemfiles/4.2.awsv1.gemfile deleted file mode 100644 index 8b423c951..000000000 --- a/gemfiles/4.2.awsv1.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "sqlite3", "~> 1.3.8", platforms: :ruby -gem "pry" -gem "rails", "~> 4.2.0" -gem "aws-sdk", "~> 1.5" - -group :development, :test do - gem "activerecord-import" - gem "mime-types", "~> 1.16" - gem "builder" - gem "rubocop", :require => false -end - -gemspec path: "../" From d55b44561ee403f82bba08c9617668d886e51907 Mon Sep 17 00:00:00 2001 From: Tute Costa Date: Tue, 22 Dec 2015 19:54:56 -0300 Subject: [PATCH 09/30] Simplify S3 file. Doesn't need v1 branches. --- UPGRADING | 5 --- lib/paperclip/storage/s3.rb | 62 +++++++++---------------------------- 2 files changed, 14 insertions(+), 53 deletions(-) diff --git a/UPGRADING b/UPGRADING index 44a2739a3..d997a83b6 100644 --- a/UPGRADING +++ b/UPGRADING @@ -12,8 +12,3 @@ changes: note that the format of the permissions changed from using an underscore to using a hyphen. For example, `:public_read` needs to be changed to `public-read`. - -If you want to continue using an earlier version of aws-sdk, replace - aws-sdk with aws-sdk-v1 in your Gemfile. - -If both are in your Gemfile, paperclip will use aws-sdk v2. diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index 9b10e2829..0b0cd8969 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -41,7 +41,7 @@ module Storage # * +s3_permissions+: This is a String that should be one of the "canned" access # policies that S3 provides (more information can be found here: # http://docs.aws.amazon.com/AmazonS3/latest/dev/ACLOverview.html) - # The default for Paperclip is :public_read (aws-sdk v1) / public-read (aws-sdk v2). + # The default for Paperclip is public-read. # # You can set permission on a per style bases by doing the following: # :s3_permissions => { @@ -194,13 +194,11 @@ def sanitize_hash(hash) def expiring_url(time = 3600, style_name = default_style) if path(style_name) - if aws_v1? - base_options = { :expires => time, :secure => use_secure_protocol?(style_name) } - s3_object(style_name).url_for(:read, base_options.merge(s3_url_options)).to_s - else - base_options = { :expires_in => time } - s3_object(style_name).presigned_url(:get, base_options.merge(s3_url_options)).to_s - end + base_options = { expires_in: time } + s3_object(style_name).presigned_url( + :get, + base_options.merge(s3_url_options), + ).to_s else url(style_name) end @@ -244,11 +242,7 @@ def bucket_name def s3_interface @s3_interface ||= begin - config = if aws_v1? - { :s3_endpoint => s3_host_name } - else - { :region => s3_region } - end + config = { region: s3_region } if using_http_proxy? @@ -272,19 +266,11 @@ def s3_interface def obtain_s3_instance_for(options) instances = (Thread.current[:paperclip_s3_instances] ||= {}) - instances[options] ||= if aws_v1? - AWS_CLASS::S3.new(options) - else - AWS_CLASS::S3::Resource.new(options) - end + instances[options] ||= AWS_CLASS::S3::Resource.new(options) end def s3_bucket - @s3_bucket ||= if aws_v1? - s3_interface.buckets[bucket_name] - else - s3_interface.bucket(bucket_name) - end + @s3_bucket ||= s3_interface.bucket(bucket_name) end def style_name_as_path(style_name) @@ -292,11 +278,7 @@ def style_name_as_path(style_name) end def s3_object style_name = default_style - if aws_v1? - s3_bucket.objects[style_name_as_path(style_name)] - else - s3_bucket.object(style_name_as_path(style_name)) - end + s3_bucket.object style_name_as_path(style_name) end def using_http_proxy? @@ -367,11 +349,7 @@ def s3_protocol(style = default_style, with_colon = false) end def create_bucket - if aws_v1? - s3_interface.buckets.create(bucket_name) - else - s3_interface.bucket(bucket_name).create - end + s3_interface.bucket(bucket_name).create end def flush_writes #:nodoc: @@ -402,11 +380,7 @@ def flush_writes #:nodoc: write_options[:metadata] = @s3_metadata unless @s3_metadata.empty? write_options.merge!(@s3_headers) - if aws_v1? - s3_object(style).write(file, write_options) - else - s3_object(style).upload_file(file.path, write_options) - end + s3_object(style).upload_file(file.path, write_options) rescue AWS_CLASS::S3::Errors::NoSuchBucket create_bucket retry @@ -432,11 +406,7 @@ def flush_deletes #:nodoc: @queued_for_delete.each do |path| begin log("deleting #{path}") - if aws_v1? - s3_bucket.objects[path.sub(%r{\A/},'')] - else - s3_bucket.object(path.sub(%r{\A/},'')) - end.delete + s3_bucket.object(path.sub(%r{\A/}, "")).delete rescue AWS_BASE_ERROR => e # Ignore this. end @@ -447,7 +417,7 @@ def flush_deletes #:nodoc: def copy_to_local_file(style, local_dest_path) log("copying #{path(style)} to local file #{local_dest_path}") ::File.open(local_dest_path, 'wb') do |local_file| - s3_object(style).send(aws_v1? ? :read : :get) do |chunk| + s3_object(style).get do |chunk| local_file.write(chunk) end end @@ -458,10 +428,6 @@ def copy_to_local_file(style, local_dest_path) private - def aws_v1? - Gem::Version.new(AWS_CLASS::VERSION) < Gem::Version.new(2) - end - def find_credentials creds case creds when File From 51ed1364be5565a9865e82e59b6660ff21325b55 Mon Sep 17 00:00:00 2001 From: Marek L Date: Sat, 2 Jan 2016 11:37:28 +0000 Subject: [PATCH 10/30] Remove unused vars `column_(type|options)` from `remove_attachment` method These variables were introduced in: https://github.com/thoughtbot/paperclip/commit/6ea7c26512434a but their usage were canceled in: https://github.com/thoughtbot/paperclip/commit/c740fb171fe --- lib/paperclip/schema.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/paperclip/schema.rb b/lib/paperclip/schema.rb index dafb715f9..311d23920 100644 --- a/lib/paperclip/schema.rb +++ b/lib/paperclip/schema.rb @@ -38,8 +38,7 @@ def remove_attachment(table_name, *attachment_names) options = attachment_names.extract_options! attachment_names.each do |attachment_name| - COLUMNS.each_pair do |column_name, column_type| - column_options = options.merge(options[column_name.to_sym] || {}) + COLUMNS.keys.each do |column_name| remove_column(table_name, "#{attachment_name}_#{column_name}") end end From e384ccd348d174d5c5a33f1617a537a22eae12cc Mon Sep 17 00:00:00 2001 From: Marek L Date: Sat, 2 Jan 2016 12:12:58 +0000 Subject: [PATCH 11/30] Replace File.exists? with File.exist? in paperclip.gemspec File.exists? is deprecated and produces unecessary warning. --- paperclip.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paperclip.gemspec b/paperclip.gemspec index da32719cc..9a1883cbf 100644 --- a/paperclip.gemspec +++ b/paperclip.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - if File.exists?('UPGRADING') + if File.exist?('UPGRADING') s.post_install_message = File.read("UPGRADING") end From c31cd641c01970e43482bb5c465870176df0dd46 Mon Sep 17 00:00:00 2001 From: Atul Bhosale Date: Fri, 1 Jan 2016 11:24:00 +0530 Subject: [PATCH 12/30] Update copyright notices to 2016 [ci skip] --- LICENSE | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 49c7d45a3..68bcce33f 100644 --- a/LICENSE +++ b/LICENSE @@ -3,7 +3,7 @@ LICENSE The MIT License -Copyright (c) 2008-2015 Jon Yurek and thoughtbot, inc. +Copyright (c) 2008-2016 Jon Yurek and thoughtbot, inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 97a6e40ce..d66b6f64f 100644 --- a/README.md +++ b/README.md @@ -970,7 +970,7 @@ Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/grap License ------- -Paperclip is Copyright © 2008-2015 thoughtbot, inc. It is free software, and may be +Paperclip is Copyright © 2008-2016 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file. About thoughtbot From cf8aa91dbc7e380800d37c3d2c76f20eed651101 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Mon, 4 Jan 2016 15:52:22 -0500 Subject: [PATCH 13/30] Relax mimemagic version constraint to ~> 0.3.0 --- paperclip.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paperclip.gemspec b/paperclip.gemspec index 9a1883cbf..f330af1dc 100644 --- a/paperclip.gemspec +++ b/paperclip.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |s| s.add_dependency('activesupport', '>= 3.2.0') s.add_dependency('cocaine', '~> 0.5.5') s.add_dependency('mime-types') - s.add_dependency('mimemagic', '0.3.0') + s.add_dependency('mimemagic', '~> 0.3.0') s.add_development_dependency('activerecord', '>= 3.2.0') s.add_development_dependency('shoulda') From f0bd25add5a1fcb188f71802435207606641f2a0 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Mon, 23 Nov 2015 00:33:20 -0500 Subject: [PATCH 14/30] Modify the Gemfile for testing with mime-types 3 - Also modify the appraisals to be more flexibly specified. - The specs are '>= 1.16' and '< 4.0' because the major versions of mime-types have steadily restricted the supported versions of Ruby at a different rate than Rails. The Appraisal for Rails 5 can be specified as either '>= 2.0, '< 4.0' or '~> 3.0' depending on how other gems restrict mime-types versions. - mime-types 1.x supports any version of Ruby, but no longer receives any updates (it hit EOL on 27 October 2015). - mime-types 2.x supports Ruby >= 1.9.2, but will only receive security and data updates until 21 November 2017. - mime-types 3.x supports Ruby >= 2.0 and is the active development version of mime-types. - The APIs that paperclip uses are compatible between all three versions of mime-types. --- Appraisals | 8 ++++++++ Gemfile | 2 +- gemfiles/4.2.awsv2.0.gemfile | 2 +- gemfiles/4.2.awsv2.1.gemfile | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Appraisals b/Appraisals index 45342b53d..0570b5899 100644 --- a/Appraisals +++ b/Appraisals @@ -1,9 +1,17 @@ appraise "4.2.awsv2.1" do gem "rails", "~> 4.2.0" gem "aws-sdk", "~> 2.1.0" + + group :development, :test do + gem 'mime-types', '>= 1.16', '< 4' + end end appraise "4.2.awsv2.0" do gem "rails", "~> 4.2.0" gem "aws-sdk", "~> 2.0.0" + + group :development, :test do + gem 'mime-types', '>= 1.16', '< 4' + end end diff --git a/Gemfile b/Gemfile index bdeb5f71b..98ee80d44 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,7 @@ gem 'pry' # Prevents bundler from taking a long-time to resolve group :development, :test do gem 'activerecord-import' - gem 'mime-types', '~> 1.16' + gem 'mime-types' gem 'builder' gem 'rubocop', require: false end diff --git a/gemfiles/4.2.awsv2.0.gemfile b/gemfiles/4.2.awsv2.0.gemfile index 528906aec..ef705dfd6 100644 --- a/gemfiles/4.2.awsv2.0.gemfile +++ b/gemfiles/4.2.awsv2.0.gemfile @@ -9,7 +9,7 @@ gem "aws-sdk", "~> 2.0.0" group :development, :test do gem "activerecord-import" - gem "mime-types", "~> 1.16" + gem "mime-types", ">= 1.16", "< 4" gem "builder" gem "rubocop", :require => false end diff --git a/gemfiles/4.2.awsv2.1.gemfile b/gemfiles/4.2.awsv2.1.gemfile index 361cfa09c..9b52119cf 100644 --- a/gemfiles/4.2.awsv2.1.gemfile +++ b/gemfiles/4.2.awsv2.1.gemfile @@ -9,7 +9,7 @@ gem "aws-sdk", "~> 2.1.0" group :development, :test do gem "activerecord-import" - gem "mime-types", "~> 1.16" + gem "mime-types", ">= 1.16", "< 4" gem "builder" gem "rubocop", :require => false end From 53a386c57ca8e8da72a25f1808585854d8458325 Mon Sep 17 00:00:00 2001 From: Matt Brictson Date: Fri, 15 Jan 2016 12:34:37 -0800 Subject: [PATCH 15/30] Skip calculating fingerprint when it is not used The MD5 sum of an attachment is only necessary if the model has a corresponding _fingerprint column. If this column is absent, there is no need to calculate the MD5, which can be an expensive operation for large files. Accomplish this by deferring the fingerprint calculation using a block. If the _fingerprint column is absent, the block is never called, and the calculation is avoided. --- lib/paperclip/attachment.rb | 8 ++++---- spec/paperclip/attachment_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/paperclip/attachment.rb b/lib/paperclip/attachment.rb index 87f26d5a8..ae8bb27ea 100644 --- a/lib/paperclip/attachment.rb +++ b/lib/paperclip/attachment.rb @@ -427,7 +427,7 @@ def initialize_storage #:nodoc: def assign_attributes @queued_for_write[:original] = @file assign_file_information - assign_fingerprint(@file.fingerprint) + assign_fingerprint { @file.fingerprint } assign_timestamps end @@ -437,9 +437,9 @@ def assign_file_information instance_write(:file_size, @file.size) end - def assign_fingerprint(fingerprint) + def assign_fingerprint if instance_respond_to?(:fingerprint) - instance_write(:fingerprint, fingerprint) + instance_write(:fingerprint, yield) end end @@ -465,7 +465,7 @@ def dirty! def reset_file_if_original_reprocessed instance_write(:file_size, @queued_for_write[:original].size) - assign_fingerprint(@queued_for_write[:original].fingerprint) + assign_fingerprint { @queued_for_write[:original].fingerprint } reset_updater end diff --git a/spec/paperclip/attachment_spec.rb b/spec/paperclip/attachment_spec.rb index 7dbf79fed..ac8015c5a 100644 --- a/spec/paperclip/attachment_spec.rb +++ b/spec/paperclip/attachment_spec.rb @@ -1374,6 +1374,12 @@ def call(filename) end it "does not calculate fingerprint" do + Digest::MD5.stubs(:file) + @dummy.avatar = @file + expect(Digest::MD5).to have_received(:file).never + end + + it "does not assign fingerprint" do @dummy.avatar = @file assert_nil @dummy.avatar.fingerprint end From 85d9af493ab40309c12a5ad17f62d57c8b8876f2 Mon Sep 17 00:00:00 2001 From: kevcha Date: Tue, 26 Jan 2016 11:24:22 +0100 Subject: [PATCH 16/30] Remove attr_protected related specs (was removed in rails 4) --- spec/paperclip/paperclip_spec.rb | 27 --------------------------- spec/spec_helper.rb | 1 - spec/support/rails_helpers.rb | 7 ------- 3 files changed, 35 deletions(-) delete mode 100644 spec/support/rails_helpers.rb diff --git a/spec/paperclip/paperclip_spec.rb b/spec/paperclip/paperclip_spec.rb index c47dfdbc6..6d87b5b4f 100644 --- a/spec/paperclip/paperclip_spec.rb +++ b/spec/paperclip/paperclip_spec.rb @@ -123,33 +123,6 @@ class ::Four; end end end - if using_protected_attributes? - context "that is attr_protected" do - before do - Dummy.class_eval do - attr_protected :avatar - end - @dummy = Dummy.new - end - - it "does not assign the avatar on mass-set" do - @dummy.attributes = { other: "I'm set!", - avatar: @file } - - assert_equal "I'm set!", @dummy.other - assert ! @dummy.avatar? - end - - it "allows assigment on normal set" do - @dummy.other = "I'm set!" - @dummy.avatar = @file - - assert_equal "I'm set!", @dummy.other - assert @dummy.avatar? - end - end - end - context "with a subclass" do before do class ::SubDummy < Dummy; end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 887b432ad..036770123 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -37,7 +37,6 @@ config.include ModelReconstruction config.include TestData config.extend VersionHelper - config.extend RailsHelpers::ClassMethods config.mock_framework = :mocha config.before(:all) do rebuild_model diff --git a/spec/support/rails_helpers.rb b/spec/support/rails_helpers.rb deleted file mode 100644 index fb45bff1f..000000000 --- a/spec/support/rails_helpers.rb +++ /dev/null @@ -1,7 +0,0 @@ -module RailsHelpers - module ClassMethods - def using_protected_attributes? - ActiveRecord::VERSION::MAJOR < 4 - end - end -end From d7b5c594a27a2f6c375dff965f8299ac1f845a39 Mon Sep 17 00:00:00 2001 From: Mike Mangino Date: Wed, 17 Feb 2016 10:20:08 -0500 Subject: [PATCH 17/30] Fix content issue --- lib/paperclip/content_type_detector.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paperclip/content_type_detector.rb b/lib/paperclip/content_type_detector.rb index 782ed9e7c..c5405a026 100644 --- a/lib/paperclip/content_type_detector.rb +++ b/lib/paperclip/content_type_detector.rb @@ -60,7 +60,7 @@ def possible_types end def type_from_file_contents - type_from_mime_magic || type_from_file_command + type_from_file_command || type_from_mime_magic rescue Errno::ENOENT => e Paperclip.log("Error while determining content type: #{e}") SENSIBLE_DEFAULT From c38bb3168a9530514d866fc674c335e05e543a5e Mon Sep 17 00:00:00 2001 From: Tute Costa Date: Thu, 25 Feb 2016 23:34:55 -0500 Subject: [PATCH 18/30] Drop support for Ruby 2.0 as it's EOLd See https://www.ruby-lang.org/en/news/2016/02/24/support-plan-of-ruby-2-0-0-and-2-1/ --- .travis.yml | 1 - NEWS | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 17568d652..47d00e916 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ rvm: - - 2.0 - 2.1 - 2.2 diff --git a/NEWS b/NEWS index dc8ada6b3..44405deaa 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ master: +* Drops support to end-of-life'd ruby 2.0. * Improvement: Paperclip now supports aws-sdk v2 @betesh, @davetchen, https://github.com/thoughtbot/paperclip/pull/1903 From e60f00027704298455c039e111d96bcf46e12822 Mon Sep 17 00:00:00 2001 From: Tute Costa Date: Sat, 12 Mar 2016 13:55:38 -0500 Subject: [PATCH 19/30] Link v4.3 release notes to that branch Related with https://github.com/thoughtbot/paperclip/issues/2122 [ci skip] --- NEWS | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 44405deaa..c50a24e49 100644 --- a/NEWS +++ b/NEWS @@ -10,14 +10,10 @@ master: s3_region may be nested in s3_credentials, and (if not nested in s3_credentials) it may be a Proc. -4.3.1 (2015-09-09): - -* Backport of bugfix to `remove_column`, so it works in Rails 3 and 4 - c740fb171fe2f88c60b999d2a1c2122f2b8f43e9 -* Fix GeometryParser regex for usage of '@>' flag -* `url` on a unpersisted record returns default_url -* spec deprecation warnings and failures -* README adjustments +4.3 + +See patch versions in v4.3 NEWS: +https://github.com/thoughtbot/paperclip/blob/v4.3/NEWS 4.3.0 (2015-06-18): From 8e1dae7dd50b18b97bebf89cf9b40b750109b50c Mon Sep 17 00:00:00 2001 From: Erkki Eilonen Date: Wed, 23 Mar 2016 19:40:18 +0800 Subject: [PATCH 20/30] close + unlink tempfiles in various edge conditions, add an around filter to test for tempfile leakage in integration spec --- lib/paperclip/attachment.rb | 4 +++ lib/paperclip/io_adapters/abstract_adapter.rb | 2 +- .../io_adapters/attachment_adapter.rb | 8 ++++- .../media_type_spoof_detection_validator.rb | 1 + spec/paperclip/integration_spec.rb | 30 ++++++++++++++++--- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/lib/paperclip/attachment.rb b/lib/paperclip/attachment.rb index ae8bb27ea..9dcf72754 100644 --- a/lib/paperclip/attachment.rb +++ b/lib/paperclip/attachment.rb @@ -523,6 +523,10 @@ def post_process_style(name, style) #:nodoc: @queued_for_write[name] = style.processors.inject(@queued_for_write[:original]) do |file, processor| file = Paperclip.processor(processor).make(file, style.processor_options, self) intermediate_files << file unless file == @queued_for_write[:original] + # if we're processing the original, close + unlink the source tempfile + if name == :original + @queued_for_write[:original].close(true) + end file end diff --git a/lib/paperclip/io_adapters/abstract_adapter.rb b/lib/paperclip/io_adapters/abstract_adapter.rb index 189778e67..ada5dbe96 100644 --- a/lib/paperclip/io_adapters/abstract_adapter.rb +++ b/lib/paperclip/io_adapters/abstract_adapter.rb @@ -4,7 +4,7 @@ module Paperclip class AbstractAdapter OS_RESTRICTED_CHARACTERS = %r{[/:]} - attr_reader :content_type, :original_filename, :size + attr_reader :content_type, :original_filename, :size, :tempfile delegate :binmode, :binmode?, :close, :close!, :closed?, :eof?, :path, :rewind, :unlink, :to => :@tempfile alias :length :size diff --git a/lib/paperclip/io_adapters/attachment_adapter.rb b/lib/paperclip/io_adapters/attachment_adapter.rb index 8319617f6..ff7695082 100644 --- a/lib/paperclip/io_adapters/attachment_adapter.rb +++ b/lib/paperclip/io_adapters/attachment_adapter.rb @@ -24,7 +24,13 @@ def copy_to_tempfile(source) if source.staged? FileUtils.cp(source.staged_path(@style), destination.path) else - source.copy_to_local_file(@style, destination.path) + begin + source.copy_to_local_file(@style, destination.path) + rescue Errno::EACCES => e + # clean up lingering tempfile if we cannot access source file + destination.close(true) + raise + end end destination end diff --git a/lib/paperclip/validators/media_type_spoof_detection_validator.rb b/lib/paperclip/validators/media_type_spoof_detection_validator.rb index d3699acc1..4bbe9dff9 100644 --- a/lib/paperclip/validators/media_type_spoof_detection_validator.rb +++ b/lib/paperclip/validators/media_type_spoof_detection_validator.rb @@ -8,6 +8,7 @@ def validate_each(record, attribute, value) if Paperclip::MediaTypeSpoofDetector.using(adapter, value.original_filename, value.content_type).spoofed? record.errors.add(attribute, :spoofed_media_type) end + adapter.tempfile.close(true) if adapter.tempfile end end diff --git a/spec/paperclip/integration_spec.rb b/spec/paperclip/integration_spec.rb index e820e494d..b4118f272 100644 --- a/spec/paperclip/integration_spec.rb +++ b/spec/paperclip/integration_spec.rb @@ -3,14 +3,25 @@ require 'open-uri' describe 'Paperclip' do + around do |example| + files, files2 = nil, nil + files = ObjectSpace.each_object(Tempfile).select{|x| x.path && File.file?(x.path)} + example.run + files2 = ObjectSpace.each_object(Tempfile).select{|x| x.path && File.file?(x.path)} + diff = files2-files + expect(diff).to eq([]), "Leaked tempfiles: #{diff.inspect}" + end + context "Many models at once" do before do rebuild_model @file = File.new(fixture_file("5k.png"), 'rb') # Deals with `Too many open files` error - Dummy.import 100.times.map { Dummy.new avatar: @file } - Dummy.import 100.times.map { Dummy.new avatar: @file } - Dummy.import 100.times.map { Dummy.new avatar: @file } + dummies = 300.times.map { Dummy.new avatar: @file } + Dummy.import dummies + # save attachment instances to run after hooks including tempfile cleanup + # since activerecord-import does not use our usually hooked-in hooks (such as after_save) + dummies.each{|d| d.avatar.save } end after { @file.close } @@ -159,7 +170,11 @@ assert_not_equal File.size(@file.path), @dummy.avatar.size end - after { @file.close } + after do + @file.close + # save attachment instance to run after hooks (including tempfile cleanup) + @dummy.avatar.save + end end context "A model with attachments scoped under an id" do @@ -347,6 +362,8 @@ it "is not ok with bad files" do @dummy.avatar = @bad_file assert ! @dummy.valid? + # save attachment instance to run after hooks (including tempfile cleanup) + @dummy.avatar.save end it "knows the difference between good files, bad files, and not files when validating" do @@ -354,8 +371,13 @@ @d2 = Dummy.find(@dummy.id) @d2.avatar = @file assert @d2.valid?, @d2.errors.full_messages.inspect + # save attachment instance to run after hooks (including tempfile cleanup) + @d2.avatar.save + @d2.avatar = @bad_file assert ! @d2.valid? + # save attachment instance to run after hooks (including tempfile cleanup) + @d2.avatar.save end it "is able to reload without saving and not have the file disappear" do From e7b6ff5ab7ae42ea939b08c5e603a62edf2f1e20 Mon Sep 17 00:00:00 2001 From: Mike Mangino Date: Thu, 7 Apr 2016 15:02:08 -0400 Subject: [PATCH 21/30] Parallel s3 upload --- lib/paperclip/storage/s3.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index 317e9592c..d18b25616 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -355,7 +355,7 @@ def create_bucket end def flush_writes #:nodoc: - @queued_for_write.each do |style, file| + @queued_for_write.peach(10) do |style, file| retries = 0 begin log("saving #{path(style)}") From c61a64615f0e6b7e571edd3c4abdf5621710768d Mon Sep 17 00:00:00 2001 From: Mike Mangino Date: Thu, 26 May 2016 12:21:57 -0400 Subject: [PATCH 22/30] use both mime and file type --- lib/paperclip/content_type_detector.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/paperclip/content_type_detector.rb b/lib/paperclip/content_type_detector.rb index c5405a026..6c98baada 100644 --- a/lib/paperclip/content_type_detector.rb +++ b/lib/paperclip/content_type_detector.rb @@ -50,15 +50,20 @@ def empty_file? alias :empty? :empty_file? def calculated_type_matches - possible_types.select do |content_type| - content_type == type_from_file_contents - end + possible_types & types_from_file_contents end def possible_types MIME::Types.type_for(@filepath).collect(&:content_type) end + def types_from_file_contents + [type_from_file_command, type_from_mime_magic].compact + rescue Errno::ENOENT => e + Paperclip.log("Error while determining content type: #{e}") + SENSIBLE_DEFAULT + end + def type_from_file_contents type_from_file_command || type_from_mime_magic rescue Errno::ENOENT => e From 86958b68c848f413c730c3401f6ac32930e1ab7b Mon Sep 17 00:00:00 2001 From: Mike Mangino Date: Tue, 15 Nov 2016 07:54:16 -0500 Subject: [PATCH 23/30] Reduce threading --- lib/paperclip/storage/s3.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index d18b25616..11a32c915 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -355,7 +355,7 @@ def create_bucket end def flush_writes #:nodoc: - @queued_for_write.peach(10) do |style, file| + @queued_for_write.peach(3) do |style, file| retries = 0 begin log("saving #{path(style)}") From f9b3067364e7c639c1358292e13fdba93a2c2f1c Mon Sep 17 00:00:00 2001 From: Jarkko Laine Date: Tue, 7 Feb 2017 10:54:21 +0200 Subject: [PATCH 24/30] Get rid of deprecated Thread.exclusive --- lib/paperclip/storage/s3.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index 11a32c915..a806052db 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -112,8 +112,10 @@ module Storage # :s3_storage_class => :reduced_redundancy module S3 + SEMAPHORE = Mutex.new + def self.extended base - Thread.exclusive do + SEMAPHORE.synchronize do unless defined?(AWS_CLASS) begin require 'aws-sdk' From 4925569cdbca1eb4527dcb80af514fe118baf3f8 Mon Sep 17 00:00:00 2001 From: Leif Gensert Date: Tue, 4 May 2021 13:57:09 -0700 Subject: [PATCH 25/30] replace URI escape with RFC2396_Parser --- lib/paperclip/url_generator.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/paperclip/url_generator.rb b/lib/paperclip/url_generator.rb index bed60f2ab..2b528a8ee 100644 --- a/lib/paperclip/url_generator.rb +++ b/lib/paperclip/url_generator.rb @@ -2,6 +2,13 @@ module Paperclip class UrlGenerator + class << self + def encoder + @encoder ||= URI::RFC2396_Parser.new + end + delegate :escape, :unescape, to: :encoder + end + def initialize(attachment, attachment_options) @attachment = attachment @attachment_options = attachment_options @@ -61,7 +68,7 @@ def escape_url(url) if url.respond_to?(:escape) url.escape else - URI.escape(url).gsub(escape_regex){|m| "%#{m.ord.to_s(16).upcase}" } + self.class.escape(url).gsub(escape_regex){|m| "%#{m.ord.to_s(16).upcase}" } end end From a57384ef2dae81d55b29b310995240fbaa469345 Mon Sep 17 00:00:00 2001 From: Alex Tan Date: Mon, 17 Oct 2022 11:26:27 -0500 Subject: [PATCH 26/30] Use AWS SDK V3 --- Appraisals | 4 ++-- lib/paperclip/storage/s3.rb | 5 +---- spec/paperclip/storage/s3_spec.rb | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Appraisals b/Appraisals index 0570b5899..bdfd8bbc0 100644 --- a/Appraisals +++ b/Appraisals @@ -1,6 +1,6 @@ appraise "4.2.awsv2.1" do gem "rails", "~> 4.2.0" - gem "aws-sdk", "~> 2.1.0" + gem "aws-sdk-s3", "~> 1" group :development, :test do gem 'mime-types', '>= 1.16', '< 4' @@ -9,7 +9,7 @@ end appraise "4.2.awsv2.0" do gem "rails", "~> 4.2.0" - gem "aws-sdk", "~> 2.0.0" + gem "aws-sdk-s3", "~> 1" group :development, :test do gem 'mime-types', '>= 1.16', '< 4' diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index a806052db..39226642c 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -118,7 +118,7 @@ def self.extended base SEMAPHORE.synchronize do unless defined?(AWS_CLASS) begin - require 'aws-sdk' + require 'aws-sdk-s3' const_set('AWS_CLASS', defined?(::Aws) ? ::Aws : ::AWS) const_set('AWS_BASE_ERROR', defined?(::Aws) ? Aws::Errors::ServiceError : AWS::Errors::Base) @@ -129,9 +129,6 @@ def self.extended base e.message << " (You may need to install the aws-sdk gem)" raise e end - if Gem::Version.new(AWS_CLASS::VERSION) >= Gem::Version.new(2) && Gem::Version.new(AWS_CLASS::VERSION) <= Gem::Version.new("2.0.33") - raise LoadError, "paperclip does not support aws-sdk versions 2.0.0 - 2.0.33. Please upgrade aws-sdk to a newer version." - end end end diff --git a/spec/paperclip/storage/s3_spec.rb b/spec/paperclip/storage/s3_spec.rb index e5bf6856d..82fbf612e 100644 --- a/spec/paperclip/storage/s3_spec.rb +++ b/spec/paperclip/storage/s3_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'aws-sdk' +require 'aws-sdk-s3' describe Paperclip::Storage::S3 do before do From 17cdc0578916190f2ab93b4e6a1a3537cb8da54c Mon Sep 17 00:00:00 2001 From: Mike Mangino Date: Thu, 27 Apr 2023 09:01:41 -0400 Subject: [PATCH 27/30] Allow storing s3 config in each style (for bucket so far) --- lib/paperclip/locales/de.yml | 18 ++++++++++++++++++ lib/paperclip/locales/es.yml | 18 ++++++++++++++++++ lib/paperclip/locales/ja.yml | 18 ++++++++++++++++++ lib/paperclip/locales/pt-BR.yml | 18 ++++++++++++++++++ lib/paperclip/locales/tr.yml | 18 ++++++++++++++++++ lib/paperclip/locales/zh-CN.yml | 18 ++++++++++++++++++ lib/paperclip/locales/zh-HK.yml | 18 ++++++++++++++++++ lib/paperclip/locales/zh-TW.yml | 18 ++++++++++++++++++ lib/paperclip/storage/s3.rb | 21 ++++++++++++--------- 9 files changed, 156 insertions(+), 9 deletions(-) create mode 100644 lib/paperclip/locales/de.yml create mode 100644 lib/paperclip/locales/es.yml create mode 100644 lib/paperclip/locales/ja.yml create mode 100644 lib/paperclip/locales/pt-BR.yml create mode 100644 lib/paperclip/locales/tr.yml create mode 100644 lib/paperclip/locales/zh-CN.yml create mode 100644 lib/paperclip/locales/zh-HK.yml create mode 100644 lib/paperclip/locales/zh-TW.yml diff --git a/lib/paperclip/locales/de.yml b/lib/paperclip/locales/de.yml new file mode 100644 index 000000000..028f7c6eb --- /dev/null +++ b/lib/paperclip/locales/de.yml @@ -0,0 +1,18 @@ +de: + errors: + messages: + in_between: "muss zwischen %{min} und %{max} sein" + spoofed_media_type: "trägt eine Dateiendung, die nicht mit dem Inhalt der Datei übereinstimmt" + + number: + human: + storage_units: + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" diff --git a/lib/paperclip/locales/es.yml b/lib/paperclip/locales/es.yml new file mode 100644 index 000000000..53d04dfc2 --- /dev/null +++ b/lib/paperclip/locales/es.yml @@ -0,0 +1,18 @@ +es: + errors: + messages: + in_between: "debe estar entre %{min} y %{max}" + spoofed_media_type: "tiene una extensión que no coincide con su contenido" + + number: + human: + storage_units: + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" diff --git a/lib/paperclip/locales/ja.yml b/lib/paperclip/locales/ja.yml new file mode 100644 index 000000000..fb9dd9941 --- /dev/null +++ b/lib/paperclip/locales/ja.yml @@ -0,0 +1,18 @@ +ja: + errors: + messages: + in_between: "の容量は%{min}以上%{max}以下にしてください。" + spoofed_media_type: "の拡張子と内容が一致していません。" + + number: + human: + storage_units: + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" diff --git a/lib/paperclip/locales/pt-BR.yml b/lib/paperclip/locales/pt-BR.yml new file mode 100644 index 000000000..12b257d1c --- /dev/null +++ b/lib/paperclip/locales/pt-BR.yml @@ -0,0 +1,18 @@ +pt-BR: + errors: + messages: + in_between: "deve ter entre %{min} e %{max}" + spoofed_media_type: "tem uma extensão que não corresponde ao seu conteúdo" + + number: + human: + storage_units: + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" diff --git a/lib/paperclip/locales/tr.yml b/lib/paperclip/locales/tr.yml new file mode 100644 index 000000000..306423bc4 --- /dev/null +++ b/lib/paperclip/locales/tr.yml @@ -0,0 +1,18 @@ +tr: + errors: + messages: + in_between: "%{min} ile %{max} arasında olmalıdır" + spoofed_media_type: "olmaması gerektiği raporlanan içerik bulunuyor" + + number: + human: + storage_units: + format: "%n %u" + units: + byte: + one: "Bayt" + other: "Bayt" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" diff --git a/lib/paperclip/locales/zh-CN.yml b/lib/paperclip/locales/zh-CN.yml new file mode 100644 index 000000000..29a8ddeb7 --- /dev/null +++ b/lib/paperclip/locales/zh-CN.yml @@ -0,0 +1,18 @@ +zh-CN: + errors: + messages: + in_between: "文件大小必须介于 %{min} 到 %{max} 之间" + spoofed_media_type: "扩展名与内容类型不符" + + number: + human: + storage_units: + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" diff --git a/lib/paperclip/locales/zh-HK.yml b/lib/paperclip/locales/zh-HK.yml new file mode 100644 index 000000000..65cbbc807 --- /dev/null +++ b/lib/paperclip/locales/zh-HK.yml @@ -0,0 +1,18 @@ +zh-HK: + errors: + messages: + in_between: "必須介於%{min}到%{max}之間" + spoofed_media_type: "副檔名與內容類型不匹配" + + number: + human: + storage_units: + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" diff --git a/lib/paperclip/locales/zh-TW.yml b/lib/paperclip/locales/zh-TW.yml new file mode 100644 index 000000000..dc6819cbc --- /dev/null +++ b/lib/paperclip/locales/zh-TW.yml @@ -0,0 +1,18 @@ +zh-TW: + errors: + messages: + in_between: "檔案大小必須介於 %{min} 到 %{max} 之間" + spoofed_media_type: "副檔名與內容類型不符" + + number: + human: + storage_units: + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index 39226642c..e4feefe95 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -183,10 +183,10 @@ def sanitize_hash(hash) "#{attachment.s3_protocol(style, true)}//#{attachment.s3_host_alias}/#{attachment.path(style).sub(%r{\A/}, "".freeze)}" end unless Paperclip::Interpolations.respond_to? :s3_alias_url Paperclip.interpolates(:s3_path_url) do |attachment, style| - "#{attachment.s3_protocol(style, true)}//#{attachment.s3_host_name}/#{attachment.bucket_name}/#{attachment.path(style).sub(%r{\A/}, "".freeze)}" + "#{attachment.s3_protocol(style, true)}//#{attachment.s3_host_name}/#{attachment.bucket_name(style)}/#{attachment.path(style).sub(%r{\A/}, "".freeze)}" end unless Paperclip::Interpolations.respond_to? :s3_path_url Paperclip.interpolates(:s3_domain_url) do |attachment, style| - "#{attachment.s3_protocol(style, true)}//#{attachment.bucket_name}.#{attachment.s3_host_name}/#{attachment.path(style).sub(%r{\A/}, "".freeze)}" + "#{attachment.s3_protocol(style, true)}//#{attachment.bucket_name(style)}.#{attachment.s3_host_name}/#{attachment.path(style).sub(%r{\A/}, "".freeze)}" end unless Paperclip::Interpolations.respond_to? :s3_domain_url Paperclip.interpolates(:asset_host) do |attachment, style| "#{attachment.path(style).sub(%r{\A/}, "".freeze)}" @@ -235,9 +235,10 @@ def s3_url_options s3_url_options end - def bucket_name + def bucket_name(style) @bucket = @options[:bucket] || s3_credentials[:bucket] @bucket = @bucket.call(self) if @bucket.respond_to?(:call) + @bucket = styles[style][:bucket] if styles[style] && styles[style][:bucket] @bucket or raise ArgumentError, "missing required :bucket option" end @@ -270,8 +271,8 @@ def obtain_s3_instance_for(options) instances[options] ||= AWS_CLASS::S3::Resource.new(options) end - def s3_bucket - @s3_bucket ||= s3_interface.bucket(bucket_name) + def s3_bucket(style) + s3_interface.bucket(bucket_name(style)) end def style_name_as_path(style_name) @@ -279,7 +280,7 @@ def style_name_as_path(style_name) end def s3_object style_name = default_style - s3_bucket.object style_name_as_path(style_name) + s3_bucket(style_name).object style_name_as_path(style_name) end def using_http_proxy? @@ -349,8 +350,8 @@ def s3_protocol(style = default_style, with_colon = false) end end - def create_bucket - s3_interface.bucket(bucket_name).create + def create_bucket(style_name) + s3_interface.bucket(bucket_name(style_name)).create end def flush_writes #:nodoc: @@ -381,9 +382,10 @@ def flush_writes #:nodoc: write_options[:metadata] = @s3_metadata unless @s3_metadata.empty? write_options.merge!(@s3_headers) + puts "******* #{s3_object.inspect}" s3_object(style).upload_file(file.path, write_options) rescue AWS_CLASS::S3::Errors::NoSuchBucket - create_bucket + create_bucket(style) retry rescue AWS_CLASS::S3::Errors::SlowDown retries += 1 @@ -404,6 +406,7 @@ def flush_writes #:nodoc: end def flush_deletes #:nodoc: + # TODO figure out style from path @queued_for_delete.each do |path| begin log("deleting #{path}") From baa43e970ce39e0f83cbd1b14c702134177bdbc8 Mon Sep 17 00:00:00 2001 From: Mike Mangino Date: Thu, 27 Apr 2023 15:53:28 -0400 Subject: [PATCH 28/30] Add region to style --- lib/paperclip/storage/s3.rb | 39 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index e4feefe95..dcfab135d 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -216,9 +216,10 @@ def s3_host_name host_name || s3_credentials[:s3_host_name] || "s3.amazonaws.com".freeze end - def s3_region + def s3_region(style) region = @options[:s3_region] region = region.call(self) if region.is_a?(Proc) + region = styles[style][:region] if styles[style] && styles[style][:region] region || s3_credentials[:s3_region] end @@ -242,28 +243,26 @@ def bucket_name(style) @bucket or raise ArgumentError, "missing required :bucket option" end - def s3_interface - @s3_interface ||= begin - config = { region: s3_region } + def s3_interface(style) + config = { region: s3_region(style) } - if using_http_proxy? + if using_http_proxy? - proxy_opts = { :host => http_proxy_host } - proxy_opts[:port] = http_proxy_port if http_proxy_port - if http_proxy_user - userinfo = http_proxy_user.to_s - userinfo += ":#{http_proxy_password}" if http_proxy_password - proxy_opts[:userinfo] = userinfo - end - config[:proxy_uri] = URI::HTTP.build(proxy_opts) - end - - [:access_key_id, :secret_access_key, :credential_provider, :credentials].each do |opt| - config[opt] = s3_credentials[opt] if s3_credentials[opt] + proxy_opts = { :host => http_proxy_host } + proxy_opts[:port] = http_proxy_port if http_proxy_port + if http_proxy_user + userinfo = http_proxy_user.to_s + userinfo += ":#{http_proxy_password}" if http_proxy_password + proxy_opts[:userinfo] = userinfo end + config[:proxy_uri] = URI::HTTP.build(proxy_opts) + end - obtain_s3_instance_for(config.merge(@s3_options)) + [:access_key_id, :secret_access_key, :credential_provider, :credentials].each do |opt| + config[opt] = s3_credentials[opt] if s3_credentials[opt] end + + obtain_s3_instance_for(config.merge(@s3_options)) end def obtain_s3_instance_for(options) @@ -272,7 +271,7 @@ def obtain_s3_instance_for(options) end def s3_bucket(style) - s3_interface.bucket(bucket_name(style)) + s3_interface(style).bucket(bucket_name(style)) end def style_name_as_path(style_name) @@ -351,7 +350,7 @@ def s3_protocol(style = default_style, with_colon = false) end def create_bucket(style_name) - s3_interface.bucket(bucket_name(style_name)).create + s3_interface(style_name).bucket(bucket_name(style_name)).create end def flush_writes #:nodoc: From e4377f7b8abdf3f8b097e2e9eda25c0b2cba208f Mon Sep 17 00:00:00 2001 From: Mike Mangino Date: Mon, 22 May 2023 10:59:41 -0400 Subject: [PATCH 29/30] Update to make regional optional --- lib/paperclip/storage/s3.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index dcfab135d..ce1cafde0 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -216,7 +216,7 @@ def s3_host_name host_name || s3_credentials[:s3_host_name] || "s3.amazonaws.com".freeze end - def s3_region(style) + def s3_region(style = :original) region = @options[:s3_region] region = region.call(self) if region.is_a?(Proc) region = styles[style][:region] if styles[style] && styles[style][:region] @@ -236,14 +236,14 @@ def s3_url_options s3_url_options end - def bucket_name(style) + def bucket_name(style = :original) @bucket = @options[:bucket] || s3_credentials[:bucket] @bucket = @bucket.call(self) if @bucket.respond_to?(:call) @bucket = styles[style][:bucket] if styles[style] && styles[style][:bucket] @bucket or raise ArgumentError, "missing required :bucket option" end - def s3_interface(style) + def s3_interface(style = :original) config = { region: s3_region(style) } if using_http_proxy? From 704e3e05f1670d53981097c3497ef7241b2d78d6 Mon Sep 17 00:00:00 2001 From: Mike Mangino Date: Mon, 22 May 2023 13:48:14 -0400 Subject: [PATCH 30/30] Fix --- lib/paperclip/storage/s3.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index ce1cafde0..bb8772233 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -236,14 +236,14 @@ def s3_url_options s3_url_options end - def bucket_name(style = :original) + def bucket_name(style = default_style) @bucket = @options[:bucket] || s3_credentials[:bucket] @bucket = @bucket.call(self) if @bucket.respond_to?(:call) @bucket = styles[style][:bucket] if styles[style] && styles[style][:bucket] @bucket or raise ArgumentError, "missing required :bucket option" end - def s3_interface(style = :original) + def s3_interface(style = default_style) config = { region: s3_region(style) } if using_http_proxy? @@ -270,7 +270,7 @@ def obtain_s3_instance_for(options) instances[options] ||= AWS_CLASS::S3::Resource.new(options) end - def s3_bucket(style) + def s3_bucket(style = default_style) s3_interface(style).bucket(bucket_name(style)) end