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
d55b4456
Commit
d55b4456
authored
Dec 22, 2015
by
Tute Costa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify S3 file. Doesn't need v1 branches.
parent
d570f1e4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
51 deletions
+12
-51
UPGRADING
+0
-5
lib/paperclip/storage/s3.rb
+12
-46
No files found.
UPGRADING
View file @
d55b4456
...
...
@@ -12,8 +12,3 @@ changes:
note that the format of the permissions changed from using an underscore to
using a hyphen. For example, `:public_read` needs to be changed to
`public-read`.
If you want to continue using an earlier version of aws-sdk, replace
aws-sdk with aws-sdk-v1 in your Gemfile.
If both are in your Gemfile, paperclip will use aws-sdk v2.
lib/paperclip/storage/s3.rb
View file @
d55b4456
...
...
@@ -41,7 +41,7 @@ module Paperclip
# * +s3_permissions+: This is a String that should be one of the "canned" access
# policies that S3 provides (more information can be found here:
# http://docs.aws.amazon.com/AmazonS3/latest/dev/ACLOverview.html)
# The default for Paperclip is
:public_read (aws-sdk v1) / public-read (aws-sdk v2)
.
# The default for Paperclip is
public-read
.
#
# You can set permission on a per style bases by doing the following:
# :s3_permissions => {
...
...
@@ -194,13 +194,11 @@ module Paperclip
def
expiring_url
(
time
=
3600
,
style_name
=
default_style
)
if
path
(
style_name
)
if
aws_v1?
base_options
=
{
:expires
=>
time
,
:secure
=>
use_secure_protocol?
(
style_name
)
}
s3_object
(
style_name
).
url_for
(
:read
,
base_options
.
merge
(
s3_url_options
)).
to_s
else
base_options
=
{
:expires_in
=>
time
}
s3_object
(
style_name
).
presigned_url
(
:get
,
base_options
.
merge
(
s3_url_options
)).
to_s
end
base_options
=
{
expires_in:
time
}
s3_object
(
style_name
).
presigned_url
(
:get
,
base_options
.
merge
(
s3_url_options
),
).
to_s
else
url
(
style_name
)
end
...
...
@@ -244,11 +242,7 @@ module Paperclip
def
s3_interface
@s3_interface
||=
begin
config
=
if
aws_v1?
{
:s3_endpoint
=>
s3_host_name
}
else
{
:region
=>
s3_region
}
end
config
=
{
region:
s3_region
}
if
using_http_proxy?
...
...
@@ -272,19 +266,11 @@ module Paperclip
def
obtain_s3_instance_for
(
options
)
instances
=
(
Thread
.
current
[
:paperclip_s3_instances
]
||=
{})
instances
[
options
]
||=
if
aws_v1?
AWS_CLASS
::
S3
.
new
(
options
)
else
AWS_CLASS
::
S3
::
Resource
.
new
(
options
)
end
instances
[
options
]
||=
AWS_CLASS
::
S3
::
Resource
.
new
(
options
)
end
def
s3_bucket
@s3_bucket
||=
if
aws_v1?
s3_interface
.
buckets
[
bucket_name
]
else
s3_interface
.
bucket
(
bucket_name
)
end
@s3_bucket
||=
s3_interface
.
bucket
(
bucket_name
)
end
def
style_name_as_path
(
style_name
)
...
...
@@ -292,11 +278,7 @@ module Paperclip
end
def
s3_object
style_name
=
default_style
if
aws_v1?
s3_bucket
.
objects
[
style_name_as_path
(
style_name
)]
else
s3_bucket
.
object
(
style_name_as_path
(
style_name
))
end
s3_bucket
.
object
style_name_as_path
(
style_name
)
end
def
using_http_proxy?
...
...
@@ -367,12 +349,8 @@ module Paperclip
end
def
create_bucket
if
aws_v1?
s3_interface
.
buckets
.
create
(
bucket_name
)
else
s3_interface
.
bucket
(
bucket_name
).
create
end
end
def
flush_writes
#:nodoc:
@queued_for_write
.
each
do
|
style
,
file
|
...
...
@@ -402,11 +380,7 @@ module Paperclip
write_options
[
:metadata
]
=
@s3_metadata
unless
@s3_metadata
.
empty?
write_options
.
merge!
(
@s3_headers
)
if
aws_v1?
s3_object
(
style
).
write
(
file
,
write_options
)
else
s3_object
(
style
).
upload_file
(
file
.
path
,
write_options
)
end
rescue
AWS_CLASS
::
S3
::
Errors
::
NoSuchBucket
create_bucket
retry
...
...
@@ -432,11 +406,7 @@ module Paperclip
@queued_for_delete
.
each
do
|
path
|
begin
log
(
"deleting
#{
path
}
"
)
if
aws_v1?
s3_bucket
.
objects
[
path
.
sub
(
%r{
\A
/}
,
''
)]
else
s3_bucket
.
object
(
path
.
sub
(
%r{
\A
/}
,
''
))
end
.
delete
s3_bucket
.
object
(
path
.
sub
(
%r{
\A
/}
,
""
)).
delete
rescue
AWS_BASE_ERROR
=>
e
# Ignore this.
end
...
...
@@ -447,7 +417,7 @@ module Paperclip
def
copy_to_local_file
(
style
,
local_dest_path
)
log
(
"copying
#{
path
(
style
)
}
to local file
#{
local_dest_path
}
"
)
::
File
.
open
(
local_dest_path
,
'wb'
)
do
|
local_file
|
s3_object
(
style
).
send
(
aws_v1?
?
:
read
:
:get
)
do
|
chunk
|
s3_object
(
style
).
get
do
|
chunk
|
local_file
.
write
(
chunk
)
end
end
...
...
@@ -458,10 +428,6 @@ module Paperclip
private
def
aws_v1?
Gem
::
Version
.
new
(
AWS_CLASS
::
VERSION
)
<
Gem
::
Version
.
new
(
2
)
end
def
find_credentials
creds
case
creds
when
File
...
...
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