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
774cee15
Commit
774cee15
authored
Oct 19, 2011
by
Kelley Reynolds
Committed by
Prem Sichanugrist
Oct 21, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only establish an S3 connection if required.
parent
75ba69da
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
11 deletions
+27
-11
lib/paperclip/storage/s3.rb
+25
-11
test/storage/s3_test.rb
+2
-0
No files found.
lib/paperclip/storage/s3.rb
View file @
774cee15
...
...
@@ -97,11 +97,6 @@ module Paperclip
if
@http_proxy
@s3_options
.
merge!
({
:proxy
=>
@http_proxy
})
end
AWS
::
S3
::
Base
.
establish_connection!
(
@s3_options
.
merge
(
:access_key_id
=>
s3_credentials
[
:access_key_id
],
:secret_access_key
=>
s3_credentials
[
:secret_access_key
]
))
end
Paperclip
.
interpolates
(
:s3_alias_url
)
do
|
attachment
,
style
|
"
#{
attachment
.
s3_protocol
(
style
)
}
://
#{
attachment
.
s3_host_alias
}
/
#{
attachment
.
path
(
style
).
gsub
(
%r{^/}
,
""
)
}
"
...
...
@@ -118,7 +113,7 @@ module Paperclip
end
def
expiring_url
(
time
=
3600
,
style_name
=
default_style
)
AWS
::
S3
::
S3O
bject
.
url_for
(
path
(
style_name
),
bucket_name
,
:expires_in
=>
time
,
:use_ssl
=>
(
s3_protocol
(
style_name
)
==
'https'
))
s3_o
bject
.
url_for
(
path
(
style_name
),
bucket_name
,
:expires_in
=>
time
,
:use_ssl
=>
(
s3_protocol
(
style_name
)
==
'https'
))
end
def
s3_credentials
...
...
@@ -178,7 +173,7 @@ module Paperclip
def
exists?
(
style
=
default_style
)
if
original_filename
AWS
::
S3
::
S3O
bject
.
exists?
(
path
(
style
),
bucket_name
)
s3_o
bject
.
exists?
(
path
(
style
),
bucket_name
)
else
false
end
...
...
@@ -207,20 +202,20 @@ module Paperclip
basename
=
File
.
basename
(
filename
,
extname
)
file
=
Tempfile
.
new
([
basename
,
extname
])
file
.
binmode
file
.
write
(
AWS
::
S3
::
S3O
bject
.
value
(
path
(
style
),
bucket_name
))
file
.
write
(
s3_o
bject
.
value
(
path
(
style
),
bucket_name
))
file
.
rewind
return
file
end
def
create_bucket
AWS
::
S3
::
B
ucket
.
create
(
bucket_name
)
s3_b
ucket
.
create
(
bucket_name
)
end
def
flush_writes
#:nodoc:
@queued_for_write
.
each
do
|
style
,
file
|
begin
log
(
"saving
#{
path
(
style
)
}
"
)
AWS
::
S3
::
S3O
bject
.
store
(
path
(
style
),
s3_o
bject
.
store
(
path
(
style
),
file
,
bucket_name
,
{
:content_type
=>
file
.
content_type
.
to_s
.
strip
,
...
...
@@ -243,7 +238,7 @@ module Paperclip
@queued_for_delete
.
each
do
|
path
|
begin
log
(
"deleting
#{
path
}
"
)
AWS
::
S3
::
S3O
bject
.
delete
(
path
,
bucket_name
)
s3_o
bject
.
delete
(
path
,
bucket_name
)
rescue
AWS
::
S3
::
ResponseError
# Ignore this.
end
...
...
@@ -265,6 +260,25 @@ module Paperclip
end
private
:find_credentials
def
s3_object
establish_connection!
AWS
::
S3
::
S3Object
end
private
:s3_object
def
s3_bucket
establish_connection!
AWS
::
S3
::
Bucket
end
private
:s3_bucket
def
establish_connection!
@connection
||=
AWS
::
S3
::
Base
.
establish_connection!
(
@s3_options
.
merge
(
:access_key_id
=>
s3_credentials
[
:access_key_id
],
:secret_access_key
=>
s3_credentials
[
:secret_access_key
]
))
end
private
:establish_connection!
end
end
end
test/storage/s3_test.rb
View file @
774cee15
...
...
@@ -476,6 +476,7 @@ class S3Test < Test::Unit::TestCase
Dummy
.
delete_all
@dummy
=
Dummy
.
new
@dummy
.
avatar
.
send
(
:establish_connection!
)
end
should
"parse the credentials"
do
...
...
@@ -499,6 +500,7 @@ class S3Test < Test::Unit::TestCase
Dummy
.
delete_all
@dummy
=
Dummy
.
new
@dummy
.
avatar
.
send
(
:establish_connection!
)
end
should
"run the file through ERB"
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