paperclip-aws 1.6.1 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -10
- data/VERSION +1 -1
- data/lib/paperclip-aws.rb +48 -24
- data/paperclip-aws.gemspec +2 -2
- metadata +11 -11
data/README.md
CHANGED
@@ -10,16 +10,15 @@
|
|
10
10
|
* supports both `http` and `https` urls;
|
11
11
|
* supports expiring urls;
|
12
12
|
* supports different permissions for each Paperclip style;
|
13
|
-
*
|
14
|
-
* correctly sets content-type of uploaded files;
|
15
|
-
* ability to set content-disposition of uploaded files;
|
13
|
+
* supports generating urls for `read`, `write` и `delete` operations;
|
16
14
|
* **supports amazon server side encryption** (thanks to @pvertenten);
|
15
|
+
* **supports versioning**;
|
17
16
|
* highly compatible with included in Paperclip S3 storage module
|
18
17
|
|
19
18
|
|
20
19
|
## Requirements ##
|
21
20
|
|
22
|
-
* [paperclip][0] ~> 2.
|
21
|
+
* [paperclip][0] ~> 2.6
|
23
22
|
* [aws-sdk][1] >= 1.2.0
|
24
23
|
|
25
24
|
## Installation ##
|
@@ -46,7 +45,7 @@ After this add 'paperclip-aws' to your `Gemfile` or `environment.rb`
|
|
46
45
|
:secret_access_key => self.s3_config['secret_access_key'],
|
47
46
|
:endpoint => self.s3_config['endpoint']
|
48
47
|
},
|
49
|
-
:
|
48
|
+
:s3_bucket => self.s3_config['bucket'],
|
50
49
|
:s3_host_alias => self.s3_config['s3_host_alias'],
|
51
50
|
:s3_permissions => :public_read,
|
52
51
|
:s3_protocol => 'http',
|
@@ -109,12 +108,12 @@ Default protocol to use: `'http'` or `'https'`.
|
|
109
108
|
### :s3_options ###
|
110
109
|
Hash of additional options. Available options are:
|
111
110
|
|
112
|
-
* `:
|
111
|
+
* `:server_side_encryption` – `'AES256'` (the only available encryption now)
|
113
112
|
* `:storage_class` – `:standard` (default) or `:reduced_redundancy`
|
114
113
|
* `:content_disposition`
|
115
114
|
|
116
115
|
|
117
|
-
## How `paperclip-aws` creates urls?
|
116
|
+
## How `paperclip-aws` creates urls? ##
|
118
117
|
|
119
118
|
'paperclip-aws' redefines Paperclip `url` method to get object URL.
|
120
119
|
|
@@ -143,13 +142,28 @@ Supported options are:
|
|
143
142
|
|
144
143
|
Default is set to `:read`, which is the most common used.
|
145
144
|
|
146
|
-
##
|
145
|
+
## Versioning ##
|
146
|
+
|
147
|
+
'paperclip-aws' lets you easily use S3 file versioning if it is enabled for selected bucket.
|
148
|
+
To find more information about versioning and how to enable it, please follow [AWS FAQs](http://aws.amazon.com/s3/faqs/#What_is_Versioning) and [AWS S3 Docs](http://docs.amazonwebservices.com/AmazonS3/latest/dev/Versioning.html).
|
149
|
+
|
150
|
+
Also you can enable versioning from your Rails console by using following code:
|
151
|
+
|
152
|
+
some_s3_attachment.data.bucket.enable_versioning
|
153
|
+
|
154
|
+
Please make sure, that user that is used to connect to S3 has enough permissions to do this, or you will get `AWS::S3::Errors::AccessDenied` error.
|
155
|
+
|
156
|
+
To get array of file versions use #versions method:
|
157
|
+
|
158
|
+
some_s3_attachment.data.versions()
|
159
|
+
|
160
|
+
## Can I use it in production? ##
|
147
161
|
|
148
162
|
Yes, usage of **paperclip-aws** is confirmed by several rather big projects:
|
149
163
|
|
150
164
|
* [www.sdelki.ru](http://www.sdelki.ru)
|
151
|
-
* [www.lienlog.com](http://www.lienlog.com)
|
152
|
-
* [www.sharypic.com](http://www.sharypic.com)
|
165
|
+
* [www.lienlog.com](http://www.lienlog.com)
|
166
|
+
* [www.sharypic.com](http://www.sharypic.com)
|
153
167
|
|
154
168
|
I hope that it is used in a lot of other projects, if you know them – let me know.
|
155
169
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.5
|
data/lib/paperclip-aws.rb
CHANGED
@@ -18,12 +18,12 @@ module Paperclip
|
|
18
18
|
attr_accessor :s3_credentials, :s3_bucket, :s3_permissions, :s3_options, :s3_protocol, :s3_host_alias
|
19
19
|
|
20
20
|
base.instance_eval do
|
21
|
-
self.
|
22
|
-
self.
|
23
|
-
self.
|
24
|
-
self.setup_s3_protocol
|
21
|
+
self.setup_s3_credentials
|
22
|
+
self.setup_s3_bucket
|
23
|
+
self.setup_s3_permissions
|
24
|
+
self.setup_s3_protocol
|
25
25
|
self.setup_s3_options
|
26
|
-
self.setup_s3_host_alias
|
26
|
+
self.setup_s3_host_alias
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -58,13 +58,34 @@ module Paperclip
|
|
58
58
|
return URI.escape(url)
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
def bucket
|
63
|
+
@bucket ||= self.s3.buckets[@s3_bucket]
|
64
|
+
end
|
65
|
+
|
66
|
+
def s3_bucket=(value)
|
67
|
+
@bucket = nil
|
68
|
+
|
69
|
+
@s3_bucket = value
|
70
|
+
@s3_bucket = @s3_bucket.call(self) if @s3_bucket.is_a?(Proc)
|
71
|
+
end
|
72
|
+
|
73
|
+
def versions(style = default_style)
|
74
|
+
begin
|
75
|
+
return nil unless self.bucket.versioning_enabled?
|
76
|
+
self.bucket.objects[path(style)].versions
|
77
|
+
rescue AWS::S3::Errors::Base => e
|
78
|
+
log "ERROR: Error occured while fetching versions for `#{path(style)}`. Probably versions are disabled or suspended for `#{self.bucket.name}` bucket."
|
79
|
+
return nil
|
80
|
+
end
|
81
|
+
end
|
61
82
|
|
62
83
|
def exists?(style = default_style)
|
63
84
|
if path(style).nil? || path(style).to_s.strip == ""
|
64
85
|
return false
|
65
86
|
end
|
66
87
|
begin
|
67
|
-
return self.
|
88
|
+
return self.bucket.objects[path(style)].exists?
|
68
89
|
rescue AWS::S3::Errors::Base
|
69
90
|
return false
|
70
91
|
end
|
@@ -87,7 +108,7 @@ module Paperclip
|
|
87
108
|
basename = File.basename(filename, extname)
|
88
109
|
file = Tempfile.new([basename, extname])
|
89
110
|
file.binmode
|
90
|
-
file.write(self.
|
111
|
+
file.write(self.bucket.objects[path(style)].read)
|
91
112
|
file.rewind
|
92
113
|
return file
|
93
114
|
end
|
@@ -99,7 +120,7 @@ module Paperclip
|
|
99
120
|
def flush_writes #:nodoc:
|
100
121
|
@queued_for_write.each do |style, file|
|
101
122
|
begin
|
102
|
-
log
|
123
|
+
log "Saving #{path(style)}"
|
103
124
|
|
104
125
|
self.s3.buckets[@s3_bucket].objects[path(style)].write({
|
105
126
|
:file => file.path,
|
@@ -119,7 +140,7 @@ module Paperclip
|
|
119
140
|
def flush_deletes #:nodoc:
|
120
141
|
@queued_for_delete.each do |path|
|
121
142
|
begin
|
122
|
-
log
|
143
|
+
log "Deleting #{path}"
|
123
144
|
self.s3.buckets[@s3_bucket].objects[path].delete
|
124
145
|
rescue AWS::Errors::Base => e
|
125
146
|
raise
|
@@ -129,9 +150,9 @@ module Paperclip
|
|
129
150
|
end
|
130
151
|
|
131
152
|
# PRIVATE METHODS
|
132
|
-
def
|
153
|
+
def setup_s3_credentials
|
133
154
|
if @options[:s3_credentials].present?
|
134
|
-
@s3_credentials = self.
|
155
|
+
@s3_credentials = self.parse_s3_credentials(@options[:s3_credentials]).stringify_keys
|
135
156
|
env = Object.const_defined?(:Rails) ? Rails.env : nil
|
136
157
|
|
137
158
|
@s3_credentials = (@s3_credentials[env] || @s3_credentials).symbolize_keys
|
@@ -140,9 +161,9 @@ module Paperclip
|
|
140
161
|
raise ArgumentError, "missing required :s3_credentials option"
|
141
162
|
end
|
142
163
|
end
|
143
|
-
protected :
|
164
|
+
protected :setup_s3_credentials
|
144
165
|
|
145
|
-
def
|
166
|
+
def parse_s3_credentials(creds)
|
146
167
|
case creds
|
147
168
|
when File
|
148
169
|
YAML::load(ERB.new(File.read(creds.path)).result)
|
@@ -154,24 +175,27 @@ module Paperclip
|
|
154
175
|
raise ArgumentError, "Credentials are not a path, file, or hash."
|
155
176
|
end
|
156
177
|
end
|
157
|
-
protected :
|
178
|
+
protected :parse_s3_credentials
|
158
179
|
|
159
|
-
def
|
180
|
+
def setup_s3_bucket
|
160
181
|
if @options[:bucket].present?
|
161
|
-
|
162
|
-
|
182
|
+
log "DEPRECATION WARNING: Passing `:bucket` options to paperclip is deprecated. Please use `:s3_bucket` instead."
|
183
|
+
end
|
184
|
+
|
185
|
+
if @options[:s3_bucket].present? || @s3_credentials[:bucket].present? || @options[:bucket].present?
|
186
|
+
self.s3_bucket = @options[:s3_bucket] || @s3_credentials[:bucket] || @options[:bucket]
|
163
187
|
else
|
164
|
-
raise ArgumentError, "missing required :
|
188
|
+
raise ArgumentError, "missing required :s3_bucket option"
|
165
189
|
end
|
166
190
|
end
|
167
|
-
protected :
|
191
|
+
protected :setup_s3_bucket
|
168
192
|
|
169
|
-
def
|
170
|
-
@s3_permissions = self.
|
193
|
+
def setup_s3_permissions
|
194
|
+
@s3_permissions = self.parse_s3_permissions(@options[:s3_permissions])
|
171
195
|
end
|
172
|
-
protected :
|
196
|
+
protected :setup_s3_permissions
|
173
197
|
|
174
|
-
def
|
198
|
+
def parse_s3_permissions(permissions)
|
175
199
|
if permissions.is_a?(Hash)
|
176
200
|
permissions[:default] = permissions[:default] || :public_read
|
177
201
|
else
|
@@ -179,7 +203,7 @@ module Paperclip
|
|
179
203
|
end
|
180
204
|
permissions
|
181
205
|
end
|
182
|
-
protected :
|
206
|
+
protected :parse_s3_permissions
|
183
207
|
|
184
208
|
def setup_s3_protocol
|
185
209
|
@s3_protocol = @options[:s3_protocol] ||
|
data/paperclip-aws.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "paperclip-aws"
|
8
|
-
s.version = "1.6.
|
8
|
+
s.version = "1.6.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Igor Alexandrov"]
|
12
|
-
s.date = "2012-02-
|
12
|
+
s.date = "2012-02-27"
|
13
13
|
s.description = "'paperclip-aws' is a full featured storage module that supports all S3 locations (US, European and Tokio) without any additional hacking."
|
14
14
|
s.email = "igor.alexandrov@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: paperclip
|
16
|
-
requirement: &
|
16
|
+
requirement: &70288657009700 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.6.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70288657009700
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: aws-sdk
|
27
|
-
requirement: &
|
27
|
+
requirement: &70288657009200 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.2.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70288657009200
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70288657008700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.0.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70288657008700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70288657008220 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 1.6.4
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70288657008220
|
58
58
|
description: ! '''paperclip-aws'' is a full featured storage module that supports
|
59
59
|
all S3 locations (US, European and Tokio) without any additional hacking.'
|
60
60
|
email: igor.alexandrov@gmail.com
|
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
segments:
|
95
95
|
- 0
|
96
|
-
hash:
|
96
|
+
hash: -1621524216927201616
|
97
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
98
|
none: false
|
99
99
|
requirements:
|