Skip to content

Commit 572bba0

Browse files
morgothsidraval
authored andcommitted
aws-sdk-s3 instead of aws-sdk (thoughtbot#2481)
* Added support for aws-sdk-s3 gem which is now preferred way to interact with s3. Reference: https://github.com/aws/aws-sdk-ruby/blob/master/V3_UPGRADING_GUIDE.md#library-maintainer * Drop support for aws-sdk gem
1 parent de92a5a commit 572bba0

File tree

7 files changed

+17
-32
lines changed

7 files changed

+17
-32
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ Storage
567567
Paperclip ships with 3 storage adapters:
568568

569569
* File Storage
570-
* S3 Storage (via `aws-sdk`)
570+
* S3 Storage (via `aws-sdk-s3`)
571571
* Fog Storage
572572

573573
If you would like to use Paperclip with another storage, you can install these
@@ -593,10 +593,10 @@ _**NOTE**: This is a change from previous versions of Paperclip, but is overall
593593
safer choice for the default file store._
594594

595595
You may also choose to store your files using Amazon's S3 service. To do so, include
596-
the `aws-sdk` gem in your Gemfile:
596+
the `aws-sdk-s3` gem in your Gemfile:
597597

598598
```ruby
599-
gem 'aws-sdk', '~> 2.3.0'
599+
gem 'aws-sdk-s3'
600600
```
601601

602602
And then you can specify using S3 from `has_attached_file`.

features/step_definitions/rails_steps.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
gem "jruby-openssl", :platform => :jruby
1818
gem "capybara"
1919
gem "gherkin"
20-
gem "aws-sdk", "~> 2.0.0"
20+
gem "aws-sdk-s3"
2121
gem "racc", :platform => :rbx
2222
gem "rubysl", :platform => :rbx
2323
"""

lib/paperclip/storage/s3.rb

+6-15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module Storage
33
# Amazon's S3 file hosting service is a scalable, easy place to store files for
44
# distribution. You can find out more about it at http://aws.amazon.com/s3
55
#
6-
# To use Paperclip with S3, include the +aws-sdk+ gem in your Gemfile:
7-
# gem 'aws-sdk'
6+
# To use Paperclip with S3, include the +aws-sdk-s3+ gem in your Gemfile:
7+
# gem 'aws-sdk-s3'
88
# There are a few S3-specific options for has_attached_file:
99
# * +s3_credentials+: Takes a path, a File, a Hash or a Proc. The path (or File) must point
1010
# to a YAML file containing the +access_key_id+ and +secret_access_key+ that Amazon
@@ -96,7 +96,7 @@ module Storage
9696
# separate parts of your file name.
9797
# * +s3_host_name+: If you are using your bucket in Tokyo region
9898
# etc, write host_name (e.g., 's3-ap-northeast-1.amazonaws.com').
99-
# * +s3_region+: For aws-sdk v2, s3_region is required.
99+
# * +s3_region+: For aws-sdk-s3, s3_region is required.
100100
# * +s3_metadata+: These key/value pairs will be stored with the
101101
# object. This option works by prefixing each key with
102102
# "x-amz-meta-" before sending it as a header on the object
@@ -118,20 +118,16 @@ module Storage
118118
# :s3_storage_class => :REDUCED_REDUNDANCY
119119
#
120120
# Other storage classes, such as <tt>:STANDARD_IA</tt>, are also available—see the
121-
# documentation for the <tt>aws-sdk</tt> gem for the full list.
121+
# documentation for the <tt>aws-sdk-s3</tt> gem for the full list.
122122

123123
module S3
124124
def self.extended base
125125
begin
126-
require 'aws-sdk'
126+
require "aws-sdk-s3"
127127
rescue LoadError => e
128-
e.message << " (You may need to install the aws-sdk gem)"
128+
e.message << " (You may need to install the aws-sdk-s3 gem)"
129129
raise e
130130
end
131-
if Gem::Version.new(Aws::VERSION) >= Gem::Version.new(2) &&
132-
Gem::Version.new(Aws::VERSION) <= Gem::Version.new("2.0.33")
133-
raise LoadError, "paperclip does not support aws-sdk versions 2.0.0 - 2.0.33. Please upgrade aws-sdk to a newer version."
134-
end
135131

136132
base.instance_eval do
137133
@s3_options = @options[:s3_options] || {}
@@ -159,11 +155,6 @@ def self.extended base
159155

160156
@http_proxy = @options[:http_proxy] || nil
161157

162-
if @options.has_key?(:use_accelerate_endpoint) &&
163-
Gem::Version.new(Aws::VERSION) < Gem::Version.new("2.3.0")
164-
raise LoadError, ":use_accelerate_endpoint is only available from aws-sdk version 2.3.0. Please upgrade aws-sdk to a newer version."
165-
end
166-
167158
@use_accelerate_endpoint = @options[:use_accelerate_endpoint]
168159
end
169160

paperclip.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
3535
s.add_development_dependency('rspec', '~> 3.0')
3636
s.add_development_dependency('appraisal')
3737
s.add_development_dependency('mocha')
38-
s.add_development_dependency('aws-sdk', '>= 2.3.0', '< 3.0')
38+
s.add_development_dependency('aws-sdk-s3')
3939
s.add_development_dependency('bourne')
4040
s.add_development_dependency('cucumber-rails')
4141
s.add_development_dependency('cucumber-expressions', '4.0.3') # TODO: investigate failures on 4.0.4

spec/paperclip/storage/s3_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
require 'spec_helper'
2-
require 'aws-sdk'
1+
require "spec_helper"
2+
require "aws-sdk-s3"
33

44
describe Paperclip::Storage::S3 do
55
before do
@@ -237,7 +237,7 @@ def aws2_add_region
237237
end
238238
end
239239

240-
# if using aws-sdk-v2, the s3_host_name will be defined by the s3_region
240+
# the s3_host_name will be defined by the s3_region
241241
context "s3_host_name" do
242242
before do
243243
rebuild_model storage: :s3,
@@ -282,7 +282,7 @@ class << @dummy
282282
end
283283
end
284284

285-
context "use_accelerate_endpoint", if: aws_accelerate_available? do
285+
context "use_accelerate_endpoint" do
286286
context "defaults to false" do
287287
before do
288288
rebuild_model(
@@ -308,7 +308,7 @@ class << @dummy
308308
end
309309
end
310310

311-
context "set to true", if: aws_accelerate_available? do
311+
context "set to true" do
312312
before do
313313
rebuild_model(
314314
storage: :s3,
@@ -793,7 +793,7 @@ def counter
793793
end
794794
end
795795

796-
# for aws-sdk-v2 the bucket.name is determined by the :s3_region
796+
# the bucket.name is determined by the :s3_region
797797
context "Parsing S3 credentials with a s3_host_name in them" do
798798
before do
799799
rebuild_model storage: :s3,

spec/spec_helper.rb

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
config.include TestData
4040
config.include Reporting
4141
config.extend VersionHelper
42-
config.extend ConditionalFilterHelper
4342
config.mock_framework = :mocha
4443
config.before(:all) do
4544
rebuild_model

spec/support/conditional_filter_helper.rb

-5
This file was deleted.

0 commit comments

Comments
 (0)