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
de11bd94
Commit
de11bd94
authored
Nov 15, 2012
by
Jon Berke
Committed by
Jon Yurek
Dec 07, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds support for style-specific s3 headers and meta data
parent
d71cc2dd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
12 deletions
+37
-12
lib/paperclip/storage/s3.rb
+37
-12
No files found.
lib/paperclip/storage/s3.rb
View file @
de11bd94
...
...
@@ -123,18 +123,9 @@ module Paperclip
(
permission
==
:public_read
)
?
'http'
:
'https'
end
@s3_metadata
=
@options
[
:s3_metadata
]
||
{}
@s3_headers
=
@options
[
:s3_headers
]
||
{}
@s3_headers
=
@s3_headers
.
call
(
instance
)
if
@s3_headers
.
respond_to?
(
:call
)
@s3_headers
=
(
@s3_headers
).
inject
({})
do
|
headers
,(
name
,
value
)
|
case
name
.
to_s
when
/^x-amz-meta-(.*)/i
@s3_metadata
[
$1
.
downcase
]
=
value
else
name
=
name
.
to_s
.
downcase
.
sub
(
/^x-amz-/
,
''
).
tr
(
"-"
,
"_"
).
to_sym
headers
[
name
]
=
value
end
headers
end
@s3_headers
,
new_s3_metadata
=
convert_headers_to_s3_format
(
@options
[
:s3_headers
])
@s3_metadata
.
merge!
(
new_s3_metadata
)
@s3_headers
[
:storage_class
]
=
@options
[
:s3_storage_class
]
if
@options
[
:s3_storage_class
]
...
...
@@ -315,8 +306,21 @@ module Paperclip
if
@s3_server_side_encryption
write_options
[
:server_side_encryption
]
=
@s3_server_side_encryption
end
if
@options
[
:styles
][
style
].
is_a?
(
Hash
)
&&
@options
[
:styles
][
style
].
has_key?
(
:s3_headers
)
style_specific_s3_headers
,
style_specific_s3_meta
=
convert_headers_to_s3_format
(
@options
[
:styles
][
style
][
:s3_headers
])
@s3_headers
.
merge!
(
style_specific_s3_headers
)
@s3_metadata
.
merge!
(
style_specific_s3_meta
)
# Merge with meta values found in :s3_headers
end
if
@options
[
:styles
][
style
].
is_a?
(
Hash
)
&&
@options
[
:styles
][
style
].
has_key?
(
:s3_metadata
)
# Merge with style-specific :s3_metadata
@s3_metadata
.
merge!
(
@options
[
:styles
][
style
][
:s3_metadata
])
end
write_options
[
:metadata
]
=
@s3_metadata
unless
@s3_metadata
.
empty?
write_options
.
merge!
(
@s3_headers
)
s3_object
(
style
).
write
(
file
,
write_options
)
rescue
AWS
::
S3
::
Errors
::
NoSuchBucket
=>
e
create_bucket
...
...
@@ -372,6 +376,27 @@ module Paperclip
def
use_secure_protocol?
(
style_name
)
s3_protocol
(
style_name
)
==
"https"
end
# Converts http-style headers to the format needed by the aws-sdk's S3Object#write method
# Returns two hashes - s3_headers and s3_metadata
# If amazon meta data headers (x-amz-meta-*) are found in http_headers, they are passed back in the second return value
def
convert_headers_to_s3_format
(
http_headers
)
s3_headers
=
http_headers
||
{}
s3_metadata
=
{}
s3_headers
=
s3_headers
.
call
(
instance
)
if
s3_headers
.
respond_to?
(
:call
)
s3_headers
=
(
s3_headers
).
inject
({})
do
|
headers
,(
name
,
value
)
|
case
name
.
to_s
when
/^x-amz-meta-(.*)/i
s3_metadata
[
$1
.
downcase
]
=
value
else
name
=
name
.
to_s
.
downcase
.
sub
(
/^x-amz-/
,
''
).
tr
(
"-"
,
"_"
).
to_sym
headers
[
name
]
=
value
end
headers
end
return
s3_headers
,
s3_metadata
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