paperclip-azure 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/VERSION +1 -1
- data/lib/paperclip/storage/azure.rb +44 -18
- data/paperclip-azure.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8285df5718393e0e9cda5f0cfd3465eb49cd2347
|
4
|
+
data.tar.gz: 74a802a4572dbaab662b6d1bebaf5cdf750ebfce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03e5de1b225b119b900d3d64cac609bfc84859a597cb1cb710690bfb36a1b27ea0219172e7910fe539fca5cbb03c1ab417e8c6e77177b31cd56f0e6d45a6ea82
|
7
|
+
data.tar.gz: 9233945f21ebd52697428d7b472c40b13c02250569c11cb29833901235a8f68fe4e6e4f1c8dff19c763eaafef76af63309ccdb936b5dcf3e10c372c3a21b1bf8
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ Or, at the level of the model such as in the following example:
|
|
41
41
|
|
42
42
|
In the even that are using a Blob that has been configured for Private access, you will need to use the Shared Access Signature functionality of Azure. This functionality has been baked in to the `Attachment#expiring_url` method. Simply specify a time and a style and you will get a proper URL as follows:
|
43
43
|
|
44
|
-
|
44
|
+
object.attachment.expiring_url(30.minutes.since, :thumb)
|
45
45
|
|
46
46
|
For more information about Azure Shared Access Signatures, please refer to [here](http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-shared-access-signature-part-1/).
|
47
47
|
|
@@ -58,6 +58,6 @@ For more information about Azure Shared Access Signatures, please refer to [here
|
|
58
58
|
|
59
59
|
## Copyright
|
60
60
|
|
61
|
-
Copyright (c) 2015
|
61
|
+
Copyright (c) 2015. See [LICENSE](LICENSE.txt) for
|
62
62
|
further details.
|
63
63
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -86,6 +86,11 @@ module Paperclip
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
+
def auto_connect_duration
|
90
|
+
@auto_connect_duration ||= @options[:auto_connect_duration] || azure_credentials[:auto_connect_duration] || 10
|
91
|
+
@auto_connect_duration
|
92
|
+
end
|
93
|
+
|
89
94
|
def azure_credentials
|
90
95
|
@azure_credentials ||= parse_credentials(@options[:azure_credentials])
|
91
96
|
end
|
@@ -135,7 +140,7 @@ module Paperclip
|
|
135
140
|
end
|
136
141
|
|
137
142
|
def azure_container
|
138
|
-
@azure_container ||= azure_interface.get_container_properties container_name
|
143
|
+
@azure_container ||= with_azure_error_handling { azure_interface.get_container_properties container_name }
|
139
144
|
end
|
140
145
|
|
141
146
|
def azure_object(style_name = default_style)
|
@@ -162,7 +167,7 @@ module Paperclip
|
|
162
167
|
end
|
163
168
|
|
164
169
|
def create_container
|
165
|
-
azure_interface.create_container container_name
|
170
|
+
with_azure_error_handling { azure_interface.create_container container_name }
|
166
171
|
end
|
167
172
|
|
168
173
|
def flush_writes #:nodoc:
|
@@ -191,19 +196,21 @@ module Paperclip
|
|
191
196
|
end
|
192
197
|
|
193
198
|
def save_blob(container_name, storage_path, file)
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
199
|
+
with_azure_error_handling do
|
200
|
+
if file.size < 64.megabytes
|
201
|
+
azure_interface.create_block_blob container_name, storage_path, file.read
|
202
|
+
else
|
203
|
+
blocks = []; count = 0
|
204
|
+
while data = file.read(4.megabytes)
|
205
|
+
block_id = "block_#{(count += 1).to_s.rjust(5, '0')}"
|
206
|
+
|
207
|
+
azure_interface.create_blob_block container_name, storage_path, block_id, data
|
208
|
+
|
209
|
+
blocks << [block_id]
|
210
|
+
end
|
205
211
|
|
206
|
-
|
212
|
+
azure_interface.commit_blob_blocks container_name, storage_path, blocks
|
213
|
+
end
|
207
214
|
end
|
208
215
|
end
|
209
216
|
|
@@ -211,7 +218,8 @@ module Paperclip
|
|
211
218
|
@queued_for_delete.each do |path|
|
212
219
|
begin
|
213
220
|
log("deleting #{path}")
|
214
|
-
|
221
|
+
|
222
|
+
with_azure_error_handling { azure_interface.delete_blob container_name, path }
|
215
223
|
rescue ::Azure::Core::Http::HTTPError => e
|
216
224
|
raise unless e.status_code == 404
|
217
225
|
end
|
@@ -222,10 +230,12 @@ module Paperclip
|
|
222
230
|
def copy_to_local_file(style, local_dest_path)
|
223
231
|
log("copying #{path(style)} to local file #{local_dest_path}")
|
224
232
|
|
225
|
-
|
233
|
+
with_azure_error_handling do
|
234
|
+
blob, content = azure_interface.get_blob(container_name, path(style).sub(%r{\A/},''))
|
226
235
|
|
227
|
-
|
228
|
-
|
236
|
+
::File.open(local_dest_path, 'wb') do |local_file|
|
237
|
+
local_file.write(content)
|
238
|
+
end
|
229
239
|
end
|
230
240
|
rescue ::Azure::Core::Http::HTTPError => e
|
231
241
|
raise unless e.status_code == 404
|
@@ -250,6 +260,22 @@ module Paperclip
|
|
250
260
|
raise ArgumentError, "Credentials given are not a path, file, proc, or hash."
|
251
261
|
end
|
252
262
|
end
|
263
|
+
|
264
|
+
def with_azure_error_handling
|
265
|
+
count = 0
|
266
|
+
|
267
|
+
begin
|
268
|
+
yield
|
269
|
+
rescue Exception => e
|
270
|
+
if count <= auto_connect_duration
|
271
|
+
sleep 2** count
|
272
|
+
count += 1
|
273
|
+
retry
|
274
|
+
end
|
275
|
+
|
276
|
+
raise
|
277
|
+
end
|
278
|
+
end
|
253
279
|
end
|
254
280
|
end
|
255
281
|
end
|
data/paperclip-azure.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "paperclip-azure"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jordan Yaker", "Supportify, Inc."]
|
12
|
-
s.date = "2015-01-
|
12
|
+
s.date = "2015-01-29"
|
13
13
|
s.description = "An Azure Blob Storage implementation for Paperclip."
|
14
14
|
s.email = "help@supportify.io"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-azure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Yaker
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-01-
|
12
|
+
date: 2015-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: azure
|