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
25be0b25
Commit
25be0b25
authored
Mar 23, 2016
by
Tute Costa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Paperclip::Storage::S3 simplification
We don't support AWS SDK v1 any longer.
parent
4adcbeda
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
26 deletions
+13
-26
features/step_definitions/s3_steps.rb
+2
-6
lib/paperclip/storage/s3.rb
+11
-20
spec/paperclip/storage/s3_spec.rb
+0
-0
No files found.
features/step_definitions/s3_steps.rb
View file @
25be0b25
When
/^I attach the file "([^"]*)" to "([^"]*)" on S3$/
do
|
file_path
,
field
|
definition
=
Paperclip
::
AttachmentRegistry
.
definitions_for
(
User
)[
field
.
downcase
.
to_sym
]
path
=
if
defined?
(
::
AWS
)
"https://paperclip.s3.amazonaws.com
#{
definition
[
:path
]
}
"
else
"https://paperclip.s3-us-west-2.amazonaws.com
#{
definition
[
:path
]
}
"
end
path
=
"https://paperclip.s3-us-west-2.amazonaws.com
#{
definition
[
:path
]
}
"
path
.
gsub!
(
':filename'
,
File
.
basename
(
file_path
))
path
.
gsub!
(
/:([^\/\.]+)/
)
do
|
match
|
"([^
\/\.
]+)"
end
FakeWeb
.
register_uri
(
:put
,
Regexp
.
new
(
path
),
:body
=>
defined?
(
::
AWS
)
?
"OK"
:
"<xml></xml>"
)
FakeWeb
.
register_uri
(
:put
,
Regexp
.
new
(
path
),
:body
=>
"<xml></xml>"
)
step
"I attach the file
\"
#{
file_path
}
\"
to
\"
#{
field
}
\"
"
end
...
...
lib/paperclip/storage/s3.rb
View file @
25be0b25
...
...
@@ -113,33 +113,24 @@ module Paperclip
module
S3
def
self
.
extended
base
unless
defined?
(
AWS_CLASS
)
begin
require
'aws-sdk'
const_set
(
'AWS_CLASS'
,
defined?
(
::
Aws
)
?
::
Aws
:
::
AWS
)
const_set
(
'AWS_BASE_ERROR'
,
defined?
(
::
Aws
)
?
Aws
::
Errors
::
ServiceError
:
AWS
::
Errors
::
Base
)
const_set
(
'DEFAULT_PERMISSION'
,
defined?
(
::
AWS
)
?
:
public_read
:
:'public-read'
)
const_set
'DEFAULT_PERMISSION'
,
:"public-read"
rescue
LoadError
=>
e
e
.
message
<<
" (You may need to install the aws-sdk gem)"
raise
e
end
if
Gem
::
Version
.
new
(
AWS_CLASS
::
VERSION
)
>=
Gem
::
Version
.
new
(
2
)
&&
Gem
::
Version
.
new
(
AWS_CLASS
::
VERSION
)
<=
Gem
::
Version
.
new
(
"2.0.33"
)
raise
LoadError
,
"paperclip does not support aws-sdk versions 2.0.0 - 2.0.33. Please upgrade aws-sdk to a newer version."
end
end
# Overriding log formatter to make sure it return a UTF-8 string
if
defined?
(
AWS_CLASS
::
Core
::
LogFormatter
)
AWS_CLASS
::
Core
::
LogFormatter
.
class_eval
do
if
defined?
(
::
Aws
::
Core
::
LogFormatter
)
::
Aws
::
Core
::
LogFormatter
.
class_eval
do
def
summarize_hash
(
hash
)
hash
.
map
{
|
key
,
value
|
":
#{
key
}
=>
#{
summarize_value
(
value
)
}
"
.
force_encoding
(
'UTF-8'
)
}.
sort
.
join
(
','
)
end
end
elsif
defined?
(
AWS_CLASS
::
Core
::
ClientLogging
)
AWS_CLASS
::
Core
::
ClientLogging
.
class_eval
do
elsif
defined?
(
::
Aws
::
Core
::
ClientLogging
)
::
Aws
::
Core
::
ClientLogging
.
class_eval
do
def
sanitize_hash
(
hash
)
hash
.
map
{
|
key
,
value
|
"
#{
sanitize_value
(
key
)
}
=>
#{
sanitize_value
(
value
)
}
"
.
force_encoding
(
'UTF-8'
)
}.
sort
.
join
(
','
)
end
...
...
@@ -266,7 +257,7 @@ module Paperclip
def
obtain_s3_instance_for
(
options
)
instances
=
(
Thread
.
current
[
:paperclip_s3_instances
]
||=
{})
instances
[
options
]
||=
AWS_CLASS
::
S3
::
Resource
.
new
(
options
)
instances
[
options
]
||=
::
Aws
::
S3
::
Resource
.
new
(
options
)
end
def
s3_bucket
...
...
@@ -323,7 +314,7 @@ module Paperclip
else
false
end
rescue
A
WS_BASE_ERROR
=>
e
rescue
A
ws
::
Errors
::
ServiceError
=>
e
false
end
...
...
@@ -381,10 +372,10 @@ module Paperclip
write_options
.
merge!
(
@s3_headers
)
s3_object
(
style
).
upload_file
(
file
.
path
,
write_options
)
rescue
AWS_CLASS
::
S3
::
Errors
::
NoSuchBucket
rescue
::
Aws
::
S3
::
Errors
::
NoSuchBucket
create_bucket
retry
rescue
AWS_CLASS
::
S3
::
Errors
::
SlowDown
rescue
::
Aws
::
S3
::
Errors
::
SlowDown
retries
+=
1
if
retries
<=
5
sleep
((
2
**
retries
)
*
0.5
)
...
...
@@ -407,7 +398,7 @@ module Paperclip
begin
log
(
"deleting
#{
path
}
"
)
s3_bucket
.
object
(
path
.
sub
(
%r{
\A
/}
,
""
)).
delete
rescue
A
WS_BASE_ERROR
=>
e
rescue
A
ws
::
Errors
::
ServiceError
=>
e
# Ignore this.
end
end
...
...
@@ -421,7 +412,7 @@ module Paperclip
local_file
.
write
(
chunk
)
end
end
rescue
A
WS_BASE_ERROR
=>
e
rescue
A
ws
::
Errors
::
ServiceError
=>
e
warn
(
"
#{
e
}
- cannot copy
#{
path
(
style
)
}
to local file
#{
local_dest_path
}
"
)
false
end
...
...
spec/paperclip/storage/s3_spec.rb
View file @
25be0b25
This diff is collapsed.
Click to expand it.
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