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
6f018763
Commit
6f018763
authored
May 06, 2009
by
Marshall Sontag
Committed by
Chad Pytel
Jun 14, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding asset_host option to url for s3 storage module
parent
cbba34c2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
lib/paperclip/storage/s3.rb
+9
-3
test/storage_test.rb
+18
-0
No files found.
lib/paperclip/storage/s3.rb
View file @
6f018763
...
...
@@ -39,9 +39,9 @@ module Paperclip
# * +s3_host_alias+: The fully-qualified domain name (FQDN) that is the alias to the
# S3 domain of your bucket. Used with the :s3_alias_url url interpolation. See the
# link in the +url+ entry for more information about S3 domains and buckets.
# * +url+: There are
three
options for the S3 url. You can choose to have the bucket's name
# * +url+: There are
four
options for the S3 url. You can choose to have the bucket's name
# placed domain-style (bucket.s3.amazonaws.com) or path-style (s3.amazonaws.com/bucket).
#
Lastly, you can
specify a CNAME (which requires the CNAME to be specified as
#
You can also
specify a CNAME (which requires the CNAME to be specified as
# :s3_alias_url. You can read more about CNAMEs and S3 at
# http://docs.amazonwebservices.com/AmazonS3/latest/index.html?VirtualHosting.html
# Normally, this won't matter in the slightest and you can leave the default (which is
...
...
@@ -50,7 +50,9 @@ module Paperclip
# NOTE: If you use a CNAME for use with CloudFront, you can NOT specify https as your
# :s3_protocol; This is *not supported* by S3/CloudFront. Finally, when using the host
# alias, the :bucket parameter is ignored, as the hostname is used as the bucket name
# by S3.
# by S3. The fourth option for the S3 url is :asset_host, which uses Rails' built-in
# asset_host settings. NOTE: To get the full url from a paperclip'd object, use the
# image_path helper; this is what image_tag uses to generate the url for an img tag.
# * +path+: This is the key under the bucket in which the file will be stored. The
# URL will be constructed from the bucket and the path. This is what you will want
# to interpolate. Keys should be unique, like filenames, and despite the fact that
...
...
@@ -78,6 +80,7 @@ module Paperclip
@path
=
@path
.
gsub
(
/:url/
,
@url
)
@url
=
":s3_path_url"
end
@url
=
":asset_host"
if
@options
[
:url
].
to_s
==
":asset_host"
AWS
::
S3
::
Base
.
establish_connection!
(
@s3_options
.
merge
(
:access_key_id
=>
@s3_credentials
[
:access_key_id
],
:secret_access_key
=>
@s3_credentials
[
:secret_access_key
]
...
...
@@ -92,6 +95,9 @@ module Paperclip
Paperclip
.
interpolates
(
:s3_domain_url
)
do
|
attachment
,
style
|
"
#{
attachment
.
s3_protocol
}
://
#{
attachment
.
bucket_name
}
.s3.amazonaws.com/
#{
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{^/}
,
""
)
}
"
end
unless
Paperclip
::
Interpolations
.
respond_to?
:asset_host
end
def
expiring_url
(
time
=
3600
,
style_name
=
default_style
)
...
...
test/storage_test.rb
View file @
6f018763
...
...
@@ -114,6 +114,24 @@ class StorageTest < Test::Unit::TestCase
end
end
context
""
do
setup
do
AWS
::
S3
::
Base
.
stubs
(
:establish_connection!
)
rebuild_model
:storage
=>
:s3
,
:s3_credentials
=>
{},
:bucket
=>
"bucket"
,
:path
=>
":attachment/:basename.:extension"
,
:url
=>
":asset_host"
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
end
should
"return a relative URL for Rails to calculate assets host"
do
assert_match
%r{^avatars/stringio.txt}
,
@dummy
.
avatar
.
url
end
end
context
"Generating a secure url with an expiration"
do
setup
do
AWS
::
S3
::
Base
.
stubs
(
:establish_connection!
)
...
...
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