Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

update to use new aws-sdk version 3 structure #2560

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ Storage
Paperclip ships with 3 storage adapters:

* File Storage
* S3 Storage (via `aws-sdk`)
* S3 Storage (via `aws-sdk-s3`)
* Fog Storage

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

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

```ruby
gem 'aws-sdk', '~> 2.3.0'
gem 'aws-sdk-s3', '~> 1.8.0'
```

And then you can specify using S3 from `has_attached_file`.
Expand Down
8 changes: 3 additions & 5 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
# NOTE FOR UPGRADING FROM 4.3.0 OR EARLIER #
##################################################

Paperclip is now compatible with aws-sdk >= 2.0.0.
Paperclip now uses aws-sdk-s3 >= 1.0.0.

If you are using S3 storage, aws-sdk >= 2.0.0 requires you to make a few small
changes:
If you are using S3 storage, this version requires you to make a few small changes:

* Update your Gemfile to use the new gem `gem 'aws-sdk-s3', '~> 1.0'`
* You must set the `s3_region`
* If you are explicitly setting permissions anywhere, such as in an initializer,
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`.

For a walkthrough of upgrading from 4 to 5 and aws-sdk >= 2.0 you can watch
http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5
6 changes: 3 additions & 3 deletions gemfiles/4.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

source "https://rubygems.org"

gem "sqlite3", "~> 1.3.8", :platforms => :ruby
gem "sqlite3", "~> 1.3.8", platforms: :ruby
gem "pry"
gem "rails", "~> 4.2.0"

group :development, :test do
gem "activerecord-import"
gem "mime-types"
gem "builder"
gem "rubocop", :require => false
gem "rubocop", require: false
gem "rspec"
end

gemspec :path => "../"
gemspec path: "../"
6 changes: 3 additions & 3 deletions gemfiles/5.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

source "https://rubygems.org"

gem "sqlite3", "~> 1.3.8", :platforms => :ruby
gem "sqlite3", "~> 1.3.8", platforms: :ruby
gem "pry"
gem "rails", "~> 5.0.0"

group :development, :test do
gem "activerecord-import"
gem "mime-types"
gem "builder"
gem "rubocop", :require => false
gem "rubocop", require: false
gem "rspec"
end

gemspec :path => "../"
gemspec path: "../"
13 changes: 2 additions & 11 deletions lib/paperclip/storage/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,11 @@ module Storage
module S3
def self.extended base
begin
require 'aws-sdk'
require 'aws-sdk-s3'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

rescue LoadError => e
e.message << " (You may need to install the aws-sdk gem)"
e.message << " (You may need to install the aws-sdk-s3 gem)"
raise e
end
if Gem::Version.new(Aws::VERSION) >= Gem::Version.new(2) &&
Gem::Version.new(Aws::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

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

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

if @options.has_key?(:use_accelerate_endpoint) &&
Gem::Version.new(Aws::VERSION) < Gem::Version.new("2.3.0")
raise LoadError, ":use_accelerate_endpoint is only available from aws-sdk version 2.3.0. Please upgrade aws-sdk to a newer version."
end

@use_accelerate_endpoint = @options[:use_accelerate_endpoint]
end

Expand Down
2 changes: 1 addition & 1 deletion paperclip.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('rspec', '~> 3.0')
s.add_development_dependency('appraisal')
s.add_development_dependency('mocha')
s.add_development_dependency('aws-sdk', '>= 2.3.0', '< 3.0')
s.add_development_dependency('aws-sdk-s3', '>= 1.8.0')
s.add_development_dependency('bourne')
s.add_development_dependency('cucumber-rails')
s.add_development_dependency('cucumber-expressions', '4.0.3') # TODO: investigate failures on 4.0.4
Expand Down
6 changes: 3 additions & 3 deletions spec/paperclip/storage/s3_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'aws-sdk'
require 'aws-sdk-s3'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


describe Paperclip::Storage::S3 do
before do
Expand Down Expand Up @@ -282,7 +282,7 @@ class << @dummy
end
end

context "use_accelerate_endpoint", if: aws_accelerate_available? do
context "use_accelerate_endpoint" do
context "defaults to false" do
before do
rebuild_model(
Expand All @@ -308,7 +308,7 @@ class << @dummy
end
end

context "set to true", if: aws_accelerate_available? do
context "set to true" do
before do
rebuild_model(
storage: :s3,
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
config.include TestData
config.include Reporting
config.extend VersionHelper
config.extend ConditionalFilterHelper
config.mock_framework = :mocha
config.before(:all) do
rebuild_model
Expand Down
5 changes: 0 additions & 5 deletions spec/support/conditional_filter_helper.rb

This file was deleted.