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
5ce04edb
Commit
5ce04edb
authored
Apr 28, 2012
by
Gonzalo Rodriguez
Committed by
Jon Yurek
May 18, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds support for S3 scheme-less URL generation
parent
c0e9b35f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
5 deletions
+42
-5
lib/paperclip/storage/s3.rb
+10
-5
test/storage/s3_test.rb
+32
-0
No files found.
lib/paperclip/storage/s3.rb
View file @
5ce04edb
...
...
@@ -39,8 +39,9 @@ module Paperclip
# :s3_permissions => :private
#
# * +s3_protocol+: The protocol for the URLs generated to your S3 assets. Can be either
# 'http' or 'https'. Defaults to 'http' when your :s3_permissions are :public_read (the
# default), and 'https' when your :s3_permissions are anything else.
# 'http', 'https', or an empty string to generate scheme-less URLs. Defaults to 'http'
# when your :s3_permissions are :public_read (the default), and 'https' when your
# :s3_permissions are anything else.
# * +s3_headers+: A hash of headers or a Proc. You may specify a hash such as
# {'Expires' => 1.year.from_now.httpdate}. If you use a Proc, headers are determined at
# runtime. Paperclip will call that Proc with attachment as the only argument.
...
...
@@ -147,14 +148,18 @@ module Paperclip
@http_proxy
=
@options
[
:http_proxy
]
||
nil
end
Paperclip
.
interpolates
(
:s3_alias_url
)
do
|
attachment
,
style
|
"
#{
attachment
.
s3_protocol
(
style
)
}
://
#{
attachment
.
s3_host_alias
}
/
#{
attachment
.
path
(
style
).
gsub
(
%r{^/}
,
""
)
}
"
url_prefix
=
(
s3_protocol
=
attachment
.
s3_protocol
(
style
)).
present?
?
"
#{
s3_protocol
}
:"
:
""
"
#{
url_prefix
}
//
#{
attachment
.
s3_host_alias
}
/
#{
attachment
.
path
(
style
).
gsub
(
%r{^/}
,
""
)
}
"
end
unless
Paperclip
::
Interpolations
.
respond_to?
:s3_alias_url
Paperclip
.
interpolates
(
:s3_path_url
)
do
|
attachment
,
style
|
"
#{
attachment
.
s3_protocol
(
style
)
}
://
#{
attachment
.
s3_host_name
}
/
#{
attachment
.
bucket_name
}
/
#{
attachment
.
path
(
style
).
gsub
(
%r{^/}
,
""
)
}
"
url_prefix
=
(
s3_protocol
=
attachment
.
s3_protocol
(
style
)).
present?
?
"
#{
s3_protocol
}
:"
:
""
"
#{
url_prefix
}
//
#{
attachment
.
s3_host_name
}
/
#{
attachment
.
bucket_name
}
/
#{
attachment
.
path
(
style
).
gsub
(
%r{^/}
,
""
)
}
"
end
unless
Paperclip
::
Interpolations
.
respond_to?
:s3_path_url
Paperclip
.
interpolates
(
:s3_domain_url
)
do
|
attachment
,
style
|
"
#{
attachment
.
s3_protocol
(
style
)
}
://
#{
attachment
.
bucket_name
}
.
#{
attachment
.
s3_host_name
}
/
#{
attachment
.
path
(
style
).
gsub
(
%r{^/}
,
""
)
}
"
url_prefix
=
(
s3_protocol
=
attachment
.
s3_protocol
(
style
)).
present?
?
"
#{
s3_protocol
}
:"
:
""
"
#{
url_prefix
}
//
#{
attachment
.
bucket_name
}
.
#{
attachment
.
s3_host_name
}
/
#{
attachment
.
path
(
style
).
gsub
(
%r{^/}
,
""
)
}
"
end
unless
Paperclip
::
Interpolations
.
respond_to?
:s3_domain_url
Paperclip
.
interpolates
(
:asset_host
)
do
|
attachment
,
style
|
"
#{
attachment
.
path
(
style
).
gsub
(
%r{^/}
,
""
)
}
"
...
...
test/storage/s3_test.rb
View file @
5ce04edb
...
...
@@ -128,6 +128,38 @@ class S3Test < Test::Unit::TestCase
end
context
":s3_protocol => 'https'"
do
setup
do
rebuild_model
:storage
=>
:s3
,
:s3_credentials
=>
{},
:s3_protocol
=>
'https'
,
:bucket
=>
"bucket"
,
:path
=>
":attachment/:basename.:extension"
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
end
should
"return a url based on an S3 path"
do
assert_match
%r{^https://s3.amazonaws.com/bucket/avatars/stringio.txt}
,
@dummy
.
avatar
.
url
end
end
context
":s3_protocol => ''"
do
setup
do
rebuild_model
:storage
=>
:s3
,
:s3_credentials
=>
{},
:s3_protocol
=>
''
,
:bucket
=>
"bucket"
,
:path
=>
":attachment/:basename.:extension"
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
end
should
"return a url based on an S3 path"
do
assert_match
%r{^//s3.amazonaws.com/bucket/avatars/stringio.txt}
,
@dummy
.
avatar
.
url
end
end
context
"An attachment that uses S3 for storage and has the style in the path"
do
setup
do
rebuild_model
:storage
=>
:s3
,
...
...
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