Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
5fa9db4d
Commit
5fa9db4d
authored
Feb 17, 2013
by
jaredmoody
Committed by
Jon Yurek
May 29, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support per style options for s3 storage class
parent
b2d9a1a9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
2 deletions
+114
-2
lib/paperclip/storage/s3.rb
+23
-1
spec/paperclip/storage/s3_spec.rb
+91
-1
No files found.
lib/paperclip/storage/s3.rb
View file @
5fa9db4d
...
...
@@ -102,6 +102,14 @@ module Paperclip
# Redundancy Storage. RRS enables customers to reduce their
# costs by storing non-critical, reproducible data at lower
# levels of redundancy than Amazon S3's standard storage.
#
# You can set storage class on a per style bases by doing the following:
# :s3_storage_class => {
# :thumb => :reduced_reduncancy
# }
# Or globally:
# :s3_storage_class => :reduced_redundancy
module
S3
def
self
.
extended
base
begin
...
...
@@ -139,7 +147,7 @@ module Paperclip
@s3_headers
=
{}
merge_s3_headers
(
@options
[
:s3_headers
],
@s3_headers
,
@s3_metadata
)
@s3_
headers
[
:storage_class
]
=
@options
[
:s3_storage_class
]
if
@options
[
:s3_storage_class
]
@s3_
storage_class
=
set_storage_class
(
@options
[
:s3_storage_class
])
@s3_server_side_encryption
=
:aes256
if
@options
[
:s3_server_side_encryption
].
blank?
...
...
@@ -272,6 +280,11 @@ module Paperclip
permissions
.
merge
:default
=>
(
permissions
[
:default
]
||
:public_read
)
end
def
set_storage_class
(
storage_class
)
storage_class
=
{
:default
=>
storage_class
}
unless
storage_class
.
respond_to?
(
:merge
)
storage_class
end
def
parse_credentials
creds
creds
=
creds
.
respond_to?
(
'call'
)
?
creds
.
call
(
self
)
:
creds
creds
=
find_credentials
(
creds
).
stringify_keys
...
...
@@ -295,6 +308,10 @@ module Paperclip
s3_permissions
end
def
s3_storage_class
(
style
=
default_style
)
@s3_storage_class
[
style
]
||
@s3_storage_class
[
:default
]
end
def
s3_protocol
(
style
=
default_style
,
with_colon
=
false
)
protocol
=
@s3_protocol
protocol
=
protocol
.
call
(
style
,
self
)
if
protocol
.
respond_to?
(
:call
)
...
...
@@ -320,6 +337,11 @@ module Paperclip
:content_type
=>
file
.
content_type
,
:acl
=>
acl
}
# add storage class for this style if defined
storage_class
=
s3_storage_class
(
style
)
write_options
.
merge!
(
:storage_class
=>
storage_class
)
if
storage_class
if
@s3_server_side_encryption
write_options
[
:server_side_encryption
]
=
@s3_server_side_encryption
end
...
...
spec/paperclip/storage/s3_spec.rb
View file @
5fa9db4d
...
...
@@ -938,7 +938,8 @@ describe Paperclip::Storage::S3 do
end
end
context
"An attachment with S3 storage and storage class set using the header name"
do
context
"An attachment with S3 storage and storage class set"
do
context
"using the header name"
do
before
do
rebuild_model
storage: :s3
,
bucket:
"testing"
,
...
...
@@ -977,6 +978,95 @@ describe Paperclip::Storage::S3 do
end
end
context
"using per style hash"
do
before
do
rebuild_model
:storage
=>
:s3
,
:bucket
=>
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
:styles
=>
{
:thumb
=>
"80x80>"
},
:s3_credentials
=>
{
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
},
:s3_storage_class
=>
{
:thumb
=>
:reduced_redundancy
}
end
context
"when assigned"
do
before
do
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
end
after
{
@file
.
close
}
context
"and saved"
do
before
do
object
=
stub
[
:thumb
,
:original
].
each
do
|
style
|
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
style
).
returns
(
object
)
expected_options
=
{
:content_type
=>
"image/png"
,
:acl
=>
:public_read
}
expected_options
.
merge!
(
:storage_class
=>
:reduced_redundancy
)
if
style
==
:thumb
object
.
expects
(
:write
).
with
(
anything
,
expected_options
)
end
@dummy
.
save
end
it
"succeeds"
do
assert
true
end
end
end
end
context
"using global hash option"
do
before
do
rebuild_model
:storage
=>
:s3
,
:bucket
=>
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
:styles
=>
{
:thumb
=>
"80x80>"
},
:s3_credentials
=>
{
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
},
:s3_storage_class
=>
:reduced_redundancy
end
context
"when assigned"
do
before
do
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
end
after
{
@file
.
close
}
context
"and saved"
do
before
do
object
=
stub
[
:thumb
,
:original
].
each
do
|
style
|
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
style
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
:acl
=>
:public_read
,
:storage_class
=>
:reduced_redundancy
)
end
@dummy
.
save
end
it
"succeeds"
do
assert
true
end
end
end
end
end
context
"Can disable AES256 encryption multiple ways"
do
[
nil
,
false
,
''
].
each
do
|
tech
|
before
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment