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
7a8d1e63
Commit
7a8d1e63
authored
Dec 14, 2011
by
iltempo
Committed by
Jon Yurek
Jan 09, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
S3 headers can be set as a proc now
parent
f56e8635
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
1 deletions
+52
-1
lib/paperclip/storage/s3.rb
+3
-1
test/storage/s3_test.rb
+49
-0
No files found.
lib/paperclip/storage/s3.rb
View file @
7a8d1e63
...
@@ -98,7 +98,9 @@ module Paperclip
...
@@ -98,7 +98,9 @@ module Paperclip
(
permission
==
:public_read
)
?
'http'
:
'https'
(
permission
==
:public_read
)
?
'http'
:
'https'
end
end
@s3_metadata
=
@options
[
:s3_metadata
]
||
{}
@s3_metadata
=
@options
[
:s3_metadata
]
||
{}
@s3_headers
=
(
@options
[
:s3_headers
]
||
{}).
inject
({})
do
|
headers
,(
name
,
value
)
|
@s3_headers
=
@options
[
:s3_headers
]
||
{}
@s3_headers
=
@s3_headers
.
call
(
instance
)
if
@s3_headers
.
is_a?
(
Proc
)
@s3_headers
=
(
@s3_headers
).
inject
({})
do
|
headers
,(
name
,
value
)
|
case
name
.
to_s
case
name
.
to_s
when
/^x-amz-meta-(.*)/i
when
/^x-amz-meta-(.*)/i
@s3_metadata
[
$1
.
downcase
]
=
value
@s3_metadata
[
$1
.
downcase
]
=
value
...
...
test/storage/s3_test.rb
View file @
7a8d1e63
...
@@ -940,4 +940,53 @@ class S3Test < Test::Unit::TestCase
...
@@ -940,4 +940,53 @@ class S3Test < Test::Unit::TestCase
end
end
end
end
context
"An attachment with S3 storage and metadata set using a proc as headers"
do
setup
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_headers
=>
lambda
{
|
attachment
|
{
'Content-Disposition'
=>
"attachment; filename=
\"
#{
attachment
.
name
}
\"
"
}
}
)
end
context
"when assigned"
do
setup
do
@file
=
File
.
new
(
fixture_file
(
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
.
stubs
(
:name
=>
'Custom Avatar Name.png'
)
@dummy
.
avatar
=
@file
end
teardown
{
@file
.
close
}
context
"and saved"
do
setup
do
[
:thumb
,
:original
].
each
do
|
style
|
object
=
stub
@dummy
.
avatar
.
stubs
(
:s3_object
).
with
(
style
).
returns
(
object
)
object
.
expects
(
:write
).
with
(
anything
,
:content_type
=>
"image/png"
,
:acl
=>
:public_read
,
:content_disposition
=>
'attachment; filename="Custom Avatar Name.png"'
)
end
@dummy
.
save
end
should
"succeed"
do
assert
true
end
end
end
end
end
end
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