azure-storage-blob 1.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/azure/storage/blob/append.rb +244 -244
- data/lib/azure/storage/blob/autoload.rb +47 -47
- data/lib/azure/storage/blob/blob.rb +932 -931
- data/lib/azure/storage/blob/blob_service.rb +720 -676
- data/lib/azure/storage/blob/block.rb +530 -530
- data/lib/azure/storage/blob/container.rb +634 -634
- data/lib/azure/storage/blob/default.rb +171 -168
- data/lib/azure/storage/blob/page.rb +566 -566
- data/lib/azure/storage/blob/serialization.rb +351 -323
- data/lib/azure/storage/blob/version.rb +49 -49
- data/lib/azure/storage/blob.rb +26 -26
- metadata +10 -30
@@ -1,566 +1,566 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#-------------------------------------------------------------------------
|
4
|
-
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
-
#
|
6
|
-
# The MIT License(MIT)
|
7
|
-
|
8
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
# of this software and associated documentation files(the "Software"), to deal
|
10
|
-
# in the Software without restriction, including without limitation the rights
|
11
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
-
# copies of the Software, and to permit persons to whom the Software is
|
13
|
-
# furnished to do so, subject to the following conditions :
|
14
|
-
|
15
|
-
# The above copyright notice and this permission notice shall be included in
|
16
|
-
# all copies or substantial portions of the Software.
|
17
|
-
|
18
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
-
# THE SOFTWARE.
|
25
|
-
#--------------------------------------------------------------------------
|
26
|
-
module Azure::Storage
|
27
|
-
module Blob
|
28
|
-
# Public: Creates a new page blob. Note that calling create_page_blob to create a page
|
29
|
-
# blob only initializes the blob. To add content to a page blob, call put_blob_pages method.
|
30
|
-
#
|
31
|
-
# ==== Attributes
|
32
|
-
#
|
33
|
-
# * +container+ - String. The container name.
|
34
|
-
# * +blob+ - String. The blob name.
|
35
|
-
# * +length+ - Integer. Specifies the maximum size for the page blob, up to 1 TB.
|
36
|
-
# The page blob size must be aligned to a 512-byte boundary.
|
37
|
-
# * +options+ - Hash. Optional parameters.
|
38
|
-
#
|
39
|
-
# ==== Options
|
40
|
-
#
|
41
|
-
# Accepted key/value pairs in options parameter are:
|
42
|
-
# * +:transactional_md5+ - String. An MD5 hash of the blob content. This hash is used to verify the integrity of the blob during transport.
|
43
|
-
# When this header is specified, the storage service checks the hash that has arrived with the one that was sent.
|
44
|
-
# If the two hashes do not match, the operation will fail with error code 400 (Bad Request).
|
45
|
-
# * +:content_type+ - String. Content type for the blob. Will be saved with blob.
|
46
|
-
# * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
|
47
|
-
# * +:content_language+ - String. Content language for the blob. Will be saved with blob.
|
48
|
-
# * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
|
49
|
-
# * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
|
50
|
-
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
51
|
-
# and also can be used to attach additional metadata
|
52
|
-
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
|
53
|
-
# * +:sequence_number+ - Integer. The sequence number is a user-controlled value that you can use to track requests.
|
54
|
-
# The value of the sequence number must be between 0 and 2^63 - 1.The default value is 0.
|
55
|
-
# * +:timeout+ - Integer. A timeout in seconds.
|
56
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
57
|
-
# in the analytics logs when storage analytics logging is enabled.
|
58
|
-
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
59
|
-
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
60
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
61
|
-
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
62
|
-
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
63
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
64
|
-
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
65
|
-
# only if the blob's ETag value matches the value specified. If the values do not match,
|
66
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
67
|
-
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
68
|
-
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
69
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
70
|
-
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
71
|
-
# specify the valid lease ID for this header.
|
72
|
-
#
|
73
|
-
# See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
|
74
|
-
#
|
75
|
-
# Returns a Blob
|
76
|
-
def create_page_blob(container, blob, length, options = {})
|
77
|
-
query = {}
|
78
|
-
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
79
|
-
|
80
|
-
uri = blob_uri(container, blob, query)
|
81
|
-
|
82
|
-
headers = {}
|
83
|
-
|
84
|
-
# set x-ms-blob-type to PageBlob
|
85
|
-
StorageService.with_header headers, "x-ms-blob-type", "PageBlob"
|
86
|
-
|
87
|
-
# ensure content-length is 0 and x-ms-blob-content-length is the blob length
|
88
|
-
StorageService.with_header headers, "Content-Length", 0.to_s
|
89
|
-
StorageService.with_header headers, "x-ms-blob-content-length", length.to_s
|
90
|
-
|
91
|
-
# set x-ms-sequence-number from options (or default to 0)
|
92
|
-
StorageService.with_header headers, "x-ms-sequence-number", (options[:sequence_number] || 0).to_s
|
93
|
-
|
94
|
-
# set the rest of the optional headers
|
95
|
-
StorageService.with_header headers, "Content-MD5", options[:transactional_md5]
|
96
|
-
StorageService.with_header headers, "x-ms-blob-content-type", options[:content_type]
|
97
|
-
StorageService.with_header headers, "x-ms-blob-content-encoding", options[:content_encoding]
|
98
|
-
StorageService.with_header headers, "x-ms-blob-content-language", options[:content_language]
|
99
|
-
StorageService.with_header headers, "x-ms-blob-content-md5", options[:content_md5]
|
100
|
-
StorageService.with_header headers, "x-ms-blob-cache-control", options[:cache_control]
|
101
|
-
StorageService.with_header headers, "x-ms-blob-content-disposition", options[:content_disposition]
|
102
|
-
|
103
|
-
StorageService.add_metadata_to_headers options[:metadata], headers
|
104
|
-
add_blob_conditional_headers options, headers
|
105
|
-
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
106
|
-
headers["x-ms-blob-content-type"] = Default::CONTENT_TYPE_VALUE unless headers["x-ms-blob-content-type"]
|
107
|
-
|
108
|
-
# call PutBlob with empty body
|
109
|
-
response = call(:put, uri, nil, headers, options)
|
110
|
-
|
111
|
-
result = Serialization.blob_from_headers(response.headers)
|
112
|
-
result.name = blob
|
113
|
-
result.metadata = options[:metadata] if options[:metadata]
|
114
|
-
|
115
|
-
result
|
116
|
-
end
|
117
|
-
|
118
|
-
# Public: Creates a range of pages in a page blob.
|
119
|
-
#
|
120
|
-
# ==== Attributes
|
121
|
-
#
|
122
|
-
# * +container+ - String. Name of container
|
123
|
-
# * +blob+ - String. Name of blob
|
124
|
-
# * +start_range+ - Integer. Position of first byte of first page
|
125
|
-
# * +end_range+ - Integer. Position of last byte of of last page
|
126
|
-
# * +content+ - IO or String. Content to write. Length in bytes should equal end_range - start_range + 1
|
127
|
-
# * +options+ - Hash. A collection of options.
|
128
|
-
#
|
129
|
-
# ==== Options
|
130
|
-
#
|
131
|
-
# Accepted key/value pairs in options parameter are:
|
132
|
-
# * +:transactional_md5+ - String. An MD5 hash of the page content. This hash is used to verify the integrity of the page during transport.
|
133
|
-
# When this header is specified, the storage service checks the hash that has arrived with the one that was sent.
|
134
|
-
# * +:if_sequence_number_le+ - Integer. If the blob's sequence number is less than or equal to the specified value, the request proceeds;
|
135
|
-
# otherwise it fails with the SequenceNumberConditionNotMet error (HTTP status code 412 - Precondition Failed).
|
136
|
-
# * +:if_sequence_number_lt+ - Integer. If the blob's sequence number is less than the specified value, the request proceeds;
|
137
|
-
# otherwise it fails with SequenceNumberConditionNotMet error (HTTP status code 412 - Precondition Failed).
|
138
|
-
# * +:if_sequence_number_eq+ - Integer. If the blob's sequence number is equal to the specified value, the request proceeds;
|
139
|
-
# otherwise it fails with SequenceNumberConditionNotMet error (HTTP status code 412 - Precondition Failed).
|
140
|
-
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to write the page only if
|
141
|
-
# the blob has been modified since the specified date/time. If the blob has not been modified,
|
142
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
143
|
-
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to write the page only if
|
144
|
-
# the blob has not been modified since the specified date/time. If the blob has been modified,
|
145
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
146
|
-
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to write the page only if
|
147
|
-
# the blob's ETag value matches the value specified. If the values do not match,
|
148
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
149
|
-
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to write the page only if
|
150
|
-
# the blob's ETag value does not match the value specified. If the values are identical,
|
151
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
152
|
-
# * +:timeout+ - Integer. A timeout in seconds.
|
153
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
154
|
-
# in the analytics logs when storage analytics logging is enabled.
|
155
|
-
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
156
|
-
# specify the valid lease ID for this header.
|
157
|
-
#
|
158
|
-
# See http://msdn.microsoft.com/en-us/library/azure/ee691975.aspx
|
159
|
-
#
|
160
|
-
# Returns Blob
|
161
|
-
def put_blob_pages(container, blob, start_range, end_range, content, options = {})
|
162
|
-
query = { "comp" => "page" }
|
163
|
-
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
164
|
-
|
165
|
-
uri = blob_uri(container, blob, query)
|
166
|
-
headers = {}
|
167
|
-
StorageService.with_header headers, "Content-MD5", options[:transactional_md5]
|
168
|
-
StorageService.with_header headers, "x-ms-range", "bytes=#{start_range}-#{end_range}"
|
169
|
-
StorageService.with_header headers, "x-ms-page-write", "update"
|
170
|
-
|
171
|
-
# clear default content type
|
172
|
-
StorageService.with_header headers, "Content-Type", ""
|
173
|
-
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
174
|
-
|
175
|
-
# set optional headers
|
176
|
-
unless options.empty?
|
177
|
-
add_blob_conditional_headers options, headers
|
178
|
-
end
|
179
|
-
|
180
|
-
response = call(:put, uri, content, headers, options)
|
181
|
-
|
182
|
-
result = Serialization.blob_from_headers(response.headers)
|
183
|
-
result.name = blob
|
184
|
-
|
185
|
-
result
|
186
|
-
end
|
187
|
-
|
188
|
-
# Public: Clears a range of pages from the blob.
|
189
|
-
#
|
190
|
-
# ==== Attributes
|
191
|
-
#
|
192
|
-
# * +container+ - String. Name of container.
|
193
|
-
# * +blob+ - String. Name of blob.
|
194
|
-
# * +start_range+ - Integer. Position of first byte of first page.
|
195
|
-
# * +end_range+ - Integer. Position of last byte of of last page.
|
196
|
-
# * +options+ - Hash. Optional parameters.
|
197
|
-
#
|
198
|
-
# ==== Options
|
199
|
-
#
|
200
|
-
# Accepted key/value pairs in options parameter are:
|
201
|
-
# * +:timeout+ - Integer. A timeout in seconds.
|
202
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
203
|
-
# in the analytics logs when storage analytics logging is enabled.
|
204
|
-
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to clear the page only if
|
205
|
-
# the blob has been modified since the specified date/time. If the blob has not been modified,
|
206
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
207
|
-
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to clear the page only if
|
208
|
-
# the blob has not been modified since the specified date/time. If the blob has been modified,
|
209
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
210
|
-
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to clear the page only if
|
211
|
-
# the blob's ETag value matches the value specified. If the values do not match,
|
212
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
213
|
-
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to clear the page only if
|
214
|
-
# the blob's ETag value does not match the value specified. If the values are identical,
|
215
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
216
|
-
#
|
217
|
-
# See http://msdn.microsoft.com/en-us/library/azure/ee691975.aspx
|
218
|
-
#
|
219
|
-
# Returns Blob
|
220
|
-
def clear_blob_pages(container, blob, start_range, end_range, options = {})
|
221
|
-
query = { "comp" => "page" }
|
222
|
-
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
223
|
-
|
224
|
-
uri = blob_uri(container, blob, query)
|
225
|
-
|
226
|
-
headers = {}
|
227
|
-
StorageService.with_header headers, "x-ms-range", "bytes=#{start_range}-#{end_range}"
|
228
|
-
StorageService.with_header headers, "x-ms-page-write", "clear"
|
229
|
-
|
230
|
-
# clear default content type
|
231
|
-
StorageService.with_header headers, "Content-Type", ""
|
232
|
-
|
233
|
-
# set optional headers
|
234
|
-
unless options.empty?
|
235
|
-
add_blob_conditional_headers options, headers
|
236
|
-
end
|
237
|
-
|
238
|
-
response = call(:put, uri, nil, headers, options)
|
239
|
-
|
240
|
-
result = Serialization.blob_from_headers(response.headers)
|
241
|
-
result.name = blob
|
242
|
-
|
243
|
-
result
|
244
|
-
end
|
245
|
-
|
246
|
-
# Public: Returns a list of active page ranges for a page blob. Active page ranges are
|
247
|
-
# those that have been populated with data.
|
248
|
-
#
|
249
|
-
# ==== Attributes
|
250
|
-
#
|
251
|
-
# * +container+ - String. The container name.
|
252
|
-
# * +blob+ - String. The blob name.
|
253
|
-
# * +options+ - Hash. Optional parameters.
|
254
|
-
#
|
255
|
-
# ==== Options
|
256
|
-
#
|
257
|
-
# Accepted key/value pairs in options parameter are:
|
258
|
-
# * +:start_range+ - Integer. Position of first byte of first page. (optional)
|
259
|
-
# * +:end_range+ - Integer. Position of last byte of of last page. (optional)
|
260
|
-
# * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
|
261
|
-
# retrieve information from. (optional)
|
262
|
-
# * +:timeout+ - Integer. A timeout in seconds.
|
263
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
264
|
-
# in the analytics logs when storage analytics logging is enabled.
|
265
|
-
# * +:location_mode+ - LocationMode. Specifies the location mode used to decide
|
266
|
-
# which location the request should be sent to.
|
267
|
-
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to list the pages only if
|
268
|
-
# the blob has been modified since the specified date/time. If the blob has not been modified,
|
269
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
270
|
-
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to list the pages only if
|
271
|
-
# the blob has not been modified since the specified date/time. If the blob has been modified,
|
272
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
273
|
-
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to list the pages only if
|
274
|
-
# the blob's ETag value matches the value specified. If the values do not match,
|
275
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
276
|
-
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to list the pages only if
|
277
|
-
# the blob's ETag value does not match the value specified. If the values are identical,
|
278
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
279
|
-
# * +:previous_snapshot+ - String. An opaque DateTime value that specifies that the response will contain only pages that
|
280
|
-
# were changed between target blob and previous snapshot. Changed pages include both updated and
|
281
|
-
# cleared pages. The target blob may be a snapshot, as long as the snapshot specified by this
|
282
|
-
# is the older of the two.
|
283
|
-
# * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
|
284
|
-
# following conditions are met:
|
285
|
-
# - The blob's lease is currently active.
|
286
|
-
# - The lease ID specified in the request matches that of the blob.
|
287
|
-
# If this header is specified and both of these conditions are not met, the request will fail
|
288
|
-
# and the Get Blob operation will fail with status code 412 (Precondition Failed).
|
289
|
-
#
|
290
|
-
# See http://msdn.microsoft.com/en-us/library/azure/ee691973.aspx
|
291
|
-
#
|
292
|
-
# Returns a list of page ranges in the format [ [start, end], [start, end], ... ]
|
293
|
-
#
|
294
|
-
# e.g. [ [0, 511], [512, 1024], ... ]
|
295
|
-
#
|
296
|
-
def list_page_blob_ranges(container, blob, options = {})
|
297
|
-
query = { "comp" => "pagelist" }
|
298
|
-
query.update("snapshot" => options[:snapshot]) if options[:snapshot]
|
299
|
-
query.update("prevsnapshot" => options[:previous_snapshot]) if options[:previous_snapshot]
|
300
|
-
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
301
|
-
|
302
|
-
options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
|
303
|
-
uri = blob_uri(container, blob, query, options)
|
304
|
-
|
305
|
-
options[:start_range] = 0 if options[:end_range] && (not options[:start_range])
|
306
|
-
|
307
|
-
headers = {}
|
308
|
-
StorageService.with_header headers, "x-ms-range", "bytes=#{options[:start_range]}-#{options[:end_range]}" if options[:start_range]
|
309
|
-
add_blob_conditional_headers options, headers
|
310
|
-
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
311
|
-
|
312
|
-
response = call(:get, uri, nil, headers, options)
|
313
|
-
|
314
|
-
pagelist = Serialization.page_list_from_xml(response.body)
|
315
|
-
pagelist
|
316
|
-
end
|
317
|
-
|
318
|
-
# Public: Resizes a page blob to the specified size.
|
319
|
-
#
|
320
|
-
# ==== Attributes
|
321
|
-
#
|
322
|
-
# * +container+ - String. The container name.
|
323
|
-
# * +blob+ - String. The blob name.
|
324
|
-
# * +size+ - String. The blob size. Resizes a page blob to the specified size.
|
325
|
-
# If the specified value is less than the current size of the blob,
|
326
|
-
# then all pages above the specified value are cleared.
|
327
|
-
# * +options+ - Hash. Optional parameters.
|
328
|
-
#
|
329
|
-
# ==== Options
|
330
|
-
#
|
331
|
-
# Accepted key/value pairs in options parameter are:
|
332
|
-
# * +:timeout+ - Integer. A timeout in seconds.
|
333
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
334
|
-
# in the analytics logs when storage analytics logging is enabled.
|
335
|
-
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
|
336
|
-
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
337
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
338
|
-
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
|
339
|
-
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
340
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
341
|
-
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
|
342
|
-
# only if the blob's ETag value matches the value specified. If the values do not match,
|
343
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
344
|
-
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
|
345
|
-
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
346
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
347
|
-
#
|
348
|
-
# See http://msdn.microsoft.com/en-us/library/azure/ee691966.aspx
|
349
|
-
#
|
350
|
-
# Returns nil on success.
|
351
|
-
def resize_page_blob(container, blob, size, options = {})
|
352
|
-
options = { content_length: size }.merge(options)
|
353
|
-
set_blob_properties container, blob, options
|
354
|
-
end
|
355
|
-
|
356
|
-
# Public: Copies a snapshot of the source page blob to a destination page blob. The snapshot is copied such that only
|
357
|
-
# the differential changes between the previously copied snapshot are transferred to the destination. The copied snapshots
|
358
|
-
# are complete copies of the original snapshot and can be read or copied from as usual.The destination of an incremental copy
|
359
|
-
# must either not exist, or must have been created with a previous incremental copy from the same source blob. Once created,
|
360
|
-
# the destination blob is permanently associated with the source and may only be used for incremental copies. The Get Blob
|
361
|
-
# Properties and List Blobs APIs indicate whether the blob is an incremental copy blob created in this way. Incremental
|
362
|
-
# copy blobs may not be downloaded directly. The only supported operations are Get Blob Properties, Incremental Copy Blob,
|
363
|
-
# and Delete Blob. The copied snapshots may be read and deleted as usual.
|
364
|
-
#
|
365
|
-
# ==== Attributes
|
366
|
-
#
|
367
|
-
# * +destination_container+ - String. The destination container name to copy to.
|
368
|
-
# * +destination_blob+ - String. The destination blob name to copy to.
|
369
|
-
# * +source_uri+ - String. Specifies the URI of the source page blob snapshot.
|
370
|
-
# This value is a URL of up to 2 KB in length that specifies a page blob snapshot. The
|
371
|
-
# value should be URL-encoded as it would appear in a request URI. The source blob must
|
372
|
-
# either be public or must be authenticated via a shared access signature. Here is an
|
373
|
-
# example of a source blob URL:
|
374
|
-
# https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot=<DateTime>
|
375
|
-
# * +options+ - Hash. Optional parameters.
|
376
|
-
#
|
377
|
-
# ==== Options
|
378
|
-
#
|
379
|
-
# Accepted key/value pairs in options parameter are:
|
380
|
-
# * +:metadata+ - Hash. Custom metadata values to store with the copy. If this parameter is not
|
381
|
-
# specified, the operation will copy the source blob metadata to the destination
|
382
|
-
# blob. If this parameter is specified, the destination blob is created with the
|
383
|
-
# specified metadata, and metadata is not copied from the source blob.
|
384
|
-
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to copy the blob only if the
|
385
|
-
# destination blob has been modified since the specified date/time. If the destination blob
|
386
|
-
# has not been modified, the Blob service returns status code 412 (Precondition Failed).
|
387
|
-
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to copy the blob only if the
|
388
|
-
# destination blob has not been modified since the specified date/time. If the destination
|
389
|
-
# blob has been modified, the Blob service returns status code 412 (Precondition Failed).
|
390
|
-
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to copy the blob
|
391
|
-
# only if the specified ETag value matches the ETag value for an existing destination blob.
|
392
|
-
# If the ETag for the destination blob does not match the ETag specified for If-Match,
|
393
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
394
|
-
# * +:if_none_match+ - String. An ETag value, or the wildcard character (*). Specify an ETag value for this
|
395
|
-
# conditional header to copy the blob only if the specified ETag value does not match the
|
396
|
-
# ETag value for the destination blob. Specify the wildcard character (*) to perform the
|
397
|
-
# operation only if the destination blob does not exist. If the specified condition isn't met,
|
398
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
399
|
-
# * +:timeout+ - Integer. A timeout in seconds.
|
400
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
401
|
-
# in the analytics logs when storage analytics logging is enabled.
|
402
|
-
# * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
|
403
|
-
# following conditions are met:
|
404
|
-
# - The blob's lease is currently active.
|
405
|
-
# - The lease ID specified in the request matches that of the blob.
|
406
|
-
# If this header is specified and both of these conditions are not met, the request will fail
|
407
|
-
# and the Snapshot Blob operation will fail with status code 412 (Precondition Failed).
|
408
|
-
#
|
409
|
-
# See https://docs.microsoft.com/en-us/rest/api/storageservices/incremental-copy-blob
|
410
|
-
#
|
411
|
-
# Returns a tuple of (copy_id, copy_status).
|
412
|
-
#
|
413
|
-
# * +copy_id+ - String. String identifier for this copy operation. Use with Get Blob Properties to check
|
414
|
-
# the status of this copy operation, or pass to Abort Copy Blob to abort a pending copy.
|
415
|
-
# * +copy_status+ - String. State of the copy operation. This is always pending to indicate that the copy has
|
416
|
-
# started and is in progress.
|
417
|
-
#
|
418
|
-
def incremental_copy_blob(destination_container, destination_blob, source_uri, options = {})
|
419
|
-
# query parameters
|
420
|
-
query = { Azure::Storage::Common::QueryStringConstants::COMP => Azure::Storage::Common::QueryStringConstants::INCREMENTAL_COPY }
|
421
|
-
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
422
|
-
|
423
|
-
# URI
|
424
|
-
uri = blob_uri(destination_container, destination_blob, query)
|
425
|
-
|
426
|
-
# headers
|
427
|
-
headers = {}
|
428
|
-
StorageService.with_header headers, "x-ms-copy-source", source_uri
|
429
|
-
unless options.empty?
|
430
|
-
add_blob_conditional_headers options, headers
|
431
|
-
StorageService.add_metadata_to_headers options[:metadata], headers
|
432
|
-
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
433
|
-
end
|
434
|
-
|
435
|
-
response = call(:put, uri, nil, headers, options)
|
436
|
-
return response.headers["x-ms-copy-id"], response.headers["x-ms-copy-status"]
|
437
|
-
end
|
438
|
-
|
439
|
-
# Public: Sets a page blob's sequence number.
|
440
|
-
#
|
441
|
-
# ==== Attributes
|
442
|
-
#
|
443
|
-
# * +container+ - String. The container name.
|
444
|
-
# * +blob+ - String. The blob name.
|
445
|
-
# * +action+ - Symbol. Indicates how the service should modify the sequence
|
446
|
-
# number for the blob. Required if :sequence_number is used. This property
|
447
|
-
# applies to page blobs only.
|
448
|
-
#
|
449
|
-
# Specify one of the following options for this property:
|
450
|
-
#
|
451
|
-
# * +:max+ - Sets the sequence number to be the higher of the value included with
|
452
|
-
# the request and the value currently stored for the blob.
|
453
|
-
# * +:update+ - Sets the sequence number to the value included with the request.
|
454
|
-
# * +:increment+ - Increments the value of the sequence number by 1. If specifying this
|
455
|
-
# option, do not include the sequence_number option; doing so will return
|
456
|
-
# status code 400 (Bad Request).
|
457
|
-
#
|
458
|
-
# * +number+ - Integer. Sets the blob's sequence number. The sequence number is a
|
459
|
-
# user-controlled property that you can use to track requests and manage concurrency
|
460
|
-
# issues. Required if the 'action' parameter is set to :max or :update.
|
461
|
-
# This property applies to page blobs only.
|
462
|
-
#
|
463
|
-
# Use this together with the 'action' parameter to update the blob's sequence
|
464
|
-
# number, either to the specified value or to the higher of the values specified with
|
465
|
-
# the request or currently stored with the blob.
|
466
|
-
#
|
467
|
-
# This header should not be specified if the 'action' parameter is set to :increment;
|
468
|
-
# in this case the service automatically increments the sequence number by one.
|
469
|
-
#
|
470
|
-
# To set the sequence number to a value of your choosing, this property must be specified
|
471
|
-
# together with the 'action' parameter
|
472
|
-
# * +options+ - Hash. Optional parameters.
|
473
|
-
#
|
474
|
-
# ==== Options
|
475
|
-
#
|
476
|
-
# Accepted key/value pairs in options parameter are:
|
477
|
-
# * +:timeout+ - Integer. A timeout in seconds.
|
478
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
479
|
-
# in the analytics logs when storage analytics logging is enabled.
|
480
|
-
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
|
481
|
-
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
482
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
483
|
-
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
|
484
|
-
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
485
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
486
|
-
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
|
487
|
-
# only if the blob's ETag value matches the value specified. If the values do not match,
|
488
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
489
|
-
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
|
490
|
-
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
491
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
492
|
-
#
|
493
|
-
# See http://msdn.microsoft.com/en-us/library/azure/ee691966.aspx
|
494
|
-
#
|
495
|
-
# Returns nil on success.
|
496
|
-
def set_sequence_number(container, blob, action, number, options = {})
|
497
|
-
options = { sequence_number_action: action, sequence_number: number }.merge(options)
|
498
|
-
set_blob_properties container, blob, options
|
499
|
-
end
|
500
|
-
|
501
|
-
# Public: Creates a new page blob filled with given content.
|
502
|
-
#
|
503
|
-
# ==== Attributes
|
504
|
-
#
|
505
|
-
# * +container+ - String. The container name.
|
506
|
-
# * +blob+ - String. The blob name.
|
507
|
-
# * +length+ - Integer. Specifies the maximum size for the page blob, up to 1 TB.
|
508
|
-
# The page blob size must be aligned to a 512-byte boundary.
|
509
|
-
# * +content+ - String or IO. The content to put in the page blob.
|
510
|
-
# * +options+ - Hash. Optional parameters.
|
511
|
-
#
|
512
|
-
# ==== Options
|
513
|
-
#
|
514
|
-
# Accepted key/value pairs in options parameter are:
|
515
|
-
# * +:content_type+ - String. Content type for the blob. Will be saved with blob.
|
516
|
-
# * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
|
517
|
-
# * +:content_language+ - String. Content language for the blob. Will be saved with blob.
|
518
|
-
# * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
|
519
|
-
# * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
|
520
|
-
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
521
|
-
# and also can be used to attach additional metadata
|
522
|
-
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
|
523
|
-
# * +:sequence_number+ - Integer. The sequence number is a user-controlled value that you can use to track requests.
|
524
|
-
# The value of the sequence number must be between 0 and 2^63 - 1.The default value is 0.
|
525
|
-
# * +:timeout+ - Integer. A timeout in seconds.
|
526
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
527
|
-
# in the analytics logs when storage analytics logging is enabled.
|
528
|
-
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
529
|
-
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
530
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
531
|
-
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
532
|
-
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
533
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
534
|
-
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
535
|
-
# only if the blob's ETag value matches the value specified. If the values do not match,
|
536
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
537
|
-
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
538
|
-
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
539
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
540
|
-
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
541
|
-
# specify the valid lease ID for this header.
|
542
|
-
#
|
543
|
-
# See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
|
544
|
-
#
|
545
|
-
# Returns a Blob
|
546
|
-
def create_page_blob_from_content(container, blob, length, content, options = {})
|
547
|
-
options[:content_type] = get_or_apply_content_type(content, options[:content_type])
|
548
|
-
create_page_blob(container, blob, length, options)
|
549
|
-
|
550
|
-
content = StringIO.new(content) if content.is_a? String
|
551
|
-
upload_count = (Float(length) / Float(BlobConstants::DEFAULT_WRITE_PAGE_SIZE_IN_BYTES)).ceil
|
552
|
-
|
553
|
-
for idx in 0...upload_count
|
554
|
-
start_range = idx * BlobConstants::DEFAULT_WRITE_PAGE_SIZE_IN_BYTES
|
555
|
-
end_range = start_range + BlobConstants::DEFAULT_WRITE_PAGE_SIZE_IN_BYTES - 1
|
556
|
-
end_range = (length - 1) if end_range > (length - 1)
|
557
|
-
put_blob_pages(container, blob, start_range, end_range, content.read(BlobConstants::DEFAULT_WRITE_PAGE_SIZE_IN_BYTES), lease_id: options[:lease_id])
|
558
|
-
end
|
559
|
-
|
560
|
-
get_properties_options = {}
|
561
|
-
get_properties_options[:lease_id] = options[:lease_id] if options[:lease_id]
|
562
|
-
# Get the blob properties
|
563
|
-
get_blob_properties(container, blob, get_properties_options)
|
564
|
-
end
|
565
|
-
end
|
566
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#-------------------------------------------------------------------------
|
4
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
+
#
|
6
|
+
# The MIT License(MIT)
|
7
|
+
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files(the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions :
|
14
|
+
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#--------------------------------------------------------------------------
|
26
|
+
module Azure::Storage
|
27
|
+
module Blob
|
28
|
+
# Public: Creates a new page blob. Note that calling create_page_blob to create a page
|
29
|
+
# blob only initializes the blob. To add content to a page blob, call put_blob_pages method.
|
30
|
+
#
|
31
|
+
# ==== Attributes
|
32
|
+
#
|
33
|
+
# * +container+ - String. The container name.
|
34
|
+
# * +blob+ - String. The blob name.
|
35
|
+
# * +length+ - Integer. Specifies the maximum size for the page blob, up to 1 TB.
|
36
|
+
# The page blob size must be aligned to a 512-byte boundary.
|
37
|
+
# * +options+ - Hash. Optional parameters.
|
38
|
+
#
|
39
|
+
# ==== Options
|
40
|
+
#
|
41
|
+
# Accepted key/value pairs in options parameter are:
|
42
|
+
# * +:transactional_md5+ - String. An MD5 hash of the blob content. This hash is used to verify the integrity of the blob during transport.
|
43
|
+
# When this header is specified, the storage service checks the hash that has arrived with the one that was sent.
|
44
|
+
# If the two hashes do not match, the operation will fail with error code 400 (Bad Request).
|
45
|
+
# * +:content_type+ - String. Content type for the blob. Will be saved with blob.
|
46
|
+
# * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
|
47
|
+
# * +:content_language+ - String. Content language for the blob. Will be saved with blob.
|
48
|
+
# * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
|
49
|
+
# * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
|
50
|
+
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
51
|
+
# and also can be used to attach additional metadata
|
52
|
+
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
|
53
|
+
# * +:sequence_number+ - Integer. The sequence number is a user-controlled value that you can use to track requests.
|
54
|
+
# The value of the sequence number must be between 0 and 2^63 - 1.The default value is 0.
|
55
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
56
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
57
|
+
# in the analytics logs when storage analytics logging is enabled.
|
58
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
59
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
60
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
61
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
62
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
63
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
64
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
65
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
66
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
67
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
68
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
69
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
70
|
+
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
71
|
+
# specify the valid lease ID for this header.
|
72
|
+
#
|
73
|
+
# See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
|
74
|
+
#
|
75
|
+
# Returns a Blob
|
76
|
+
def create_page_blob(container, blob, length, options = {})
|
77
|
+
query = {}
|
78
|
+
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
79
|
+
|
80
|
+
uri = blob_uri(container, blob, query)
|
81
|
+
|
82
|
+
headers = {}
|
83
|
+
|
84
|
+
# set x-ms-blob-type to PageBlob
|
85
|
+
StorageService.with_header headers, "x-ms-blob-type", "PageBlob"
|
86
|
+
|
87
|
+
# ensure content-length is 0 and x-ms-blob-content-length is the blob length
|
88
|
+
StorageService.with_header headers, "Content-Length", 0.to_s
|
89
|
+
StorageService.with_header headers, "x-ms-blob-content-length", length.to_s
|
90
|
+
|
91
|
+
# set x-ms-sequence-number from options (or default to 0)
|
92
|
+
StorageService.with_header headers, "x-ms-sequence-number", (options[:sequence_number] || 0).to_s
|
93
|
+
|
94
|
+
# set the rest of the optional headers
|
95
|
+
StorageService.with_header headers, "Content-MD5", options[:transactional_md5]
|
96
|
+
StorageService.with_header headers, "x-ms-blob-content-type", options[:content_type]
|
97
|
+
StorageService.with_header headers, "x-ms-blob-content-encoding", options[:content_encoding]
|
98
|
+
StorageService.with_header headers, "x-ms-blob-content-language", options[:content_language]
|
99
|
+
StorageService.with_header headers, "x-ms-blob-content-md5", options[:content_md5]
|
100
|
+
StorageService.with_header headers, "x-ms-blob-cache-control", options[:cache_control]
|
101
|
+
StorageService.with_header headers, "x-ms-blob-content-disposition", options[:content_disposition]
|
102
|
+
|
103
|
+
StorageService.add_metadata_to_headers options[:metadata], headers
|
104
|
+
add_blob_conditional_headers options, headers
|
105
|
+
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
106
|
+
headers["x-ms-blob-content-type"] = Default::CONTENT_TYPE_VALUE unless headers["x-ms-blob-content-type"]
|
107
|
+
|
108
|
+
# call PutBlob with empty body
|
109
|
+
response = call(:put, uri, nil, headers, options)
|
110
|
+
|
111
|
+
result = Serialization.blob_from_headers(response.headers)
|
112
|
+
result.name = blob
|
113
|
+
result.metadata = options[:metadata] if options[:metadata]
|
114
|
+
|
115
|
+
result
|
116
|
+
end
|
117
|
+
|
118
|
+
# Public: Creates a range of pages in a page blob.
|
119
|
+
#
|
120
|
+
# ==== Attributes
|
121
|
+
#
|
122
|
+
# * +container+ - String. Name of container
|
123
|
+
# * +blob+ - String. Name of blob
|
124
|
+
# * +start_range+ - Integer. Position of first byte of first page
|
125
|
+
# * +end_range+ - Integer. Position of last byte of of last page
|
126
|
+
# * +content+ - IO or String. Content to write. Length in bytes should equal end_range - start_range + 1
|
127
|
+
# * +options+ - Hash. A collection of options.
|
128
|
+
#
|
129
|
+
# ==== Options
|
130
|
+
#
|
131
|
+
# Accepted key/value pairs in options parameter are:
|
132
|
+
# * +:transactional_md5+ - String. An MD5 hash of the page content. This hash is used to verify the integrity of the page during transport.
|
133
|
+
# When this header is specified, the storage service checks the hash that has arrived with the one that was sent.
|
134
|
+
# * +:if_sequence_number_le+ - Integer. If the blob's sequence number is less than or equal to the specified value, the request proceeds;
|
135
|
+
# otherwise it fails with the SequenceNumberConditionNotMet error (HTTP status code 412 - Precondition Failed).
|
136
|
+
# * +:if_sequence_number_lt+ - Integer. If the blob's sequence number is less than the specified value, the request proceeds;
|
137
|
+
# otherwise it fails with SequenceNumberConditionNotMet error (HTTP status code 412 - Precondition Failed).
|
138
|
+
# * +:if_sequence_number_eq+ - Integer. If the blob's sequence number is equal to the specified value, the request proceeds;
|
139
|
+
# otherwise it fails with SequenceNumberConditionNotMet error (HTTP status code 412 - Precondition Failed).
|
140
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to write the page only if
|
141
|
+
# the blob has been modified since the specified date/time. If the blob has not been modified,
|
142
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
143
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to write the page only if
|
144
|
+
# the blob has not been modified since the specified date/time. If the blob has been modified,
|
145
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
146
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to write the page only if
|
147
|
+
# the blob's ETag value matches the value specified. If the values do not match,
|
148
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
149
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to write the page only if
|
150
|
+
# the blob's ETag value does not match the value specified. If the values are identical,
|
151
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
152
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
153
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
154
|
+
# in the analytics logs when storage analytics logging is enabled.
|
155
|
+
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
156
|
+
# specify the valid lease ID for this header.
|
157
|
+
#
|
158
|
+
# See http://msdn.microsoft.com/en-us/library/azure/ee691975.aspx
|
159
|
+
#
|
160
|
+
# Returns Blob
|
161
|
+
def put_blob_pages(container, blob, start_range, end_range, content, options = {})
|
162
|
+
query = { "comp" => "page" }
|
163
|
+
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
164
|
+
|
165
|
+
uri = blob_uri(container, blob, query)
|
166
|
+
headers = {}
|
167
|
+
StorageService.with_header headers, "Content-MD5", options[:transactional_md5]
|
168
|
+
StorageService.with_header headers, "x-ms-range", "bytes=#{start_range}-#{end_range}"
|
169
|
+
StorageService.with_header headers, "x-ms-page-write", "update"
|
170
|
+
|
171
|
+
# clear default content type
|
172
|
+
StorageService.with_header headers, "Content-Type", ""
|
173
|
+
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
174
|
+
|
175
|
+
# set optional headers
|
176
|
+
unless options.empty?
|
177
|
+
add_blob_conditional_headers options, headers
|
178
|
+
end
|
179
|
+
|
180
|
+
response = call(:put, uri, content, headers, options)
|
181
|
+
|
182
|
+
result = Serialization.blob_from_headers(response.headers)
|
183
|
+
result.name = blob
|
184
|
+
|
185
|
+
result
|
186
|
+
end
|
187
|
+
|
188
|
+
# Public: Clears a range of pages from the blob.
|
189
|
+
#
|
190
|
+
# ==== Attributes
|
191
|
+
#
|
192
|
+
# * +container+ - String. Name of container.
|
193
|
+
# * +blob+ - String. Name of blob.
|
194
|
+
# * +start_range+ - Integer. Position of first byte of first page.
|
195
|
+
# * +end_range+ - Integer. Position of last byte of of last page.
|
196
|
+
# * +options+ - Hash. Optional parameters.
|
197
|
+
#
|
198
|
+
# ==== Options
|
199
|
+
#
|
200
|
+
# Accepted key/value pairs in options parameter are:
|
201
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
202
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
203
|
+
# in the analytics logs when storage analytics logging is enabled.
|
204
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to clear the page only if
|
205
|
+
# the blob has been modified since the specified date/time. If the blob has not been modified,
|
206
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
207
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to clear the page only if
|
208
|
+
# the blob has not been modified since the specified date/time. If the blob has been modified,
|
209
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
210
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to clear the page only if
|
211
|
+
# the blob's ETag value matches the value specified. If the values do not match,
|
212
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
213
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to clear the page only if
|
214
|
+
# the blob's ETag value does not match the value specified. If the values are identical,
|
215
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
216
|
+
#
|
217
|
+
# See http://msdn.microsoft.com/en-us/library/azure/ee691975.aspx
|
218
|
+
#
|
219
|
+
# Returns Blob
|
220
|
+
def clear_blob_pages(container, blob, start_range, end_range, options = {})
|
221
|
+
query = { "comp" => "page" }
|
222
|
+
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
223
|
+
|
224
|
+
uri = blob_uri(container, blob, query)
|
225
|
+
|
226
|
+
headers = {}
|
227
|
+
StorageService.with_header headers, "x-ms-range", "bytes=#{start_range}-#{end_range}"
|
228
|
+
StorageService.with_header headers, "x-ms-page-write", "clear"
|
229
|
+
|
230
|
+
# clear default content type
|
231
|
+
StorageService.with_header headers, "Content-Type", ""
|
232
|
+
|
233
|
+
# set optional headers
|
234
|
+
unless options.empty?
|
235
|
+
add_blob_conditional_headers options, headers
|
236
|
+
end
|
237
|
+
|
238
|
+
response = call(:put, uri, nil, headers, options)
|
239
|
+
|
240
|
+
result = Serialization.blob_from_headers(response.headers)
|
241
|
+
result.name = blob
|
242
|
+
|
243
|
+
result
|
244
|
+
end
|
245
|
+
|
246
|
+
# Public: Returns a list of active page ranges for a page blob. Active page ranges are
|
247
|
+
# those that have been populated with data.
|
248
|
+
#
|
249
|
+
# ==== Attributes
|
250
|
+
#
|
251
|
+
# * +container+ - String. The container name.
|
252
|
+
# * +blob+ - String. The blob name.
|
253
|
+
# * +options+ - Hash. Optional parameters.
|
254
|
+
#
|
255
|
+
# ==== Options
|
256
|
+
#
|
257
|
+
# Accepted key/value pairs in options parameter are:
|
258
|
+
# * +:start_range+ - Integer. Position of first byte of first page. (optional)
|
259
|
+
# * +:end_range+ - Integer. Position of last byte of of last page. (optional)
|
260
|
+
# * +:snapshot+ - String. An opaque DateTime value that specifies the blob snapshot to
|
261
|
+
# retrieve information from. (optional)
|
262
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
263
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
264
|
+
# in the analytics logs when storage analytics logging is enabled.
|
265
|
+
# * +:location_mode+ - LocationMode. Specifies the location mode used to decide
|
266
|
+
# which location the request should be sent to.
|
267
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to list the pages only if
|
268
|
+
# the blob has been modified since the specified date/time. If the blob has not been modified,
|
269
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
270
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to list the pages only if
|
271
|
+
# the blob has not been modified since the specified date/time. If the blob has been modified,
|
272
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
273
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to list the pages only if
|
274
|
+
# the blob's ETag value matches the value specified. If the values do not match,
|
275
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
276
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to list the pages only if
|
277
|
+
# the blob's ETag value does not match the value specified. If the values are identical,
|
278
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
279
|
+
# * +:previous_snapshot+ - String. An opaque DateTime value that specifies that the response will contain only pages that
|
280
|
+
# were changed between target blob and previous snapshot. Changed pages include both updated and
|
281
|
+
# cleared pages. The target blob may be a snapshot, as long as the snapshot specified by this
|
282
|
+
# is the older of the two.
|
283
|
+
# * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
|
284
|
+
# following conditions are met:
|
285
|
+
# - The blob's lease is currently active.
|
286
|
+
# - The lease ID specified in the request matches that of the blob.
|
287
|
+
# If this header is specified and both of these conditions are not met, the request will fail
|
288
|
+
# and the Get Blob operation will fail with status code 412 (Precondition Failed).
|
289
|
+
#
|
290
|
+
# See http://msdn.microsoft.com/en-us/library/azure/ee691973.aspx
|
291
|
+
#
|
292
|
+
# Returns a list of page ranges in the format [ [start, end], [start, end], ... ]
|
293
|
+
#
|
294
|
+
# e.g. [ [0, 511], [512, 1024], ... ]
|
295
|
+
#
|
296
|
+
def list_page_blob_ranges(container, blob, options = {})
|
297
|
+
query = { "comp" => "pagelist" }
|
298
|
+
query.update("snapshot" => options[:snapshot]) if options[:snapshot]
|
299
|
+
query.update("prevsnapshot" => options[:previous_snapshot]) if options[:previous_snapshot]
|
300
|
+
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
301
|
+
|
302
|
+
options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
|
303
|
+
uri = blob_uri(container, blob, query, options)
|
304
|
+
|
305
|
+
options[:start_range] = 0 if options[:end_range] && (not options[:start_range])
|
306
|
+
|
307
|
+
headers = {}
|
308
|
+
StorageService.with_header headers, "x-ms-range", "bytes=#{options[:start_range]}-#{options[:end_range]}" if options[:start_range]
|
309
|
+
add_blob_conditional_headers options, headers
|
310
|
+
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
311
|
+
|
312
|
+
response = call(:get, uri, nil, headers, options)
|
313
|
+
|
314
|
+
pagelist = Serialization.page_list_from_xml(response.body)
|
315
|
+
pagelist
|
316
|
+
end
|
317
|
+
|
318
|
+
# Public: Resizes a page blob to the specified size.
|
319
|
+
#
|
320
|
+
# ==== Attributes
|
321
|
+
#
|
322
|
+
# * +container+ - String. The container name.
|
323
|
+
# * +blob+ - String. The blob name.
|
324
|
+
# * +size+ - String. The blob size. Resizes a page blob to the specified size.
|
325
|
+
# If the specified value is less than the current size of the blob,
|
326
|
+
# then all pages above the specified value are cleared.
|
327
|
+
# * +options+ - Hash. Optional parameters.
|
328
|
+
#
|
329
|
+
# ==== Options
|
330
|
+
#
|
331
|
+
# Accepted key/value pairs in options parameter are:
|
332
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
333
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
334
|
+
# in the analytics logs when storage analytics logging is enabled.
|
335
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
|
336
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
337
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
338
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
|
339
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
340
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
341
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
|
342
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
343
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
344
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
|
345
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
346
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
347
|
+
#
|
348
|
+
# See http://msdn.microsoft.com/en-us/library/azure/ee691966.aspx
|
349
|
+
#
|
350
|
+
# Returns nil on success.
|
351
|
+
def resize_page_blob(container, blob, size, options = {})
|
352
|
+
options = { content_length: size }.merge(options)
|
353
|
+
set_blob_properties container, blob, options
|
354
|
+
end
|
355
|
+
|
356
|
+
# Public: Copies a snapshot of the source page blob to a destination page blob. The snapshot is copied such that only
|
357
|
+
# the differential changes between the previously copied snapshot are transferred to the destination. The copied snapshots
|
358
|
+
# are complete copies of the original snapshot and can be read or copied from as usual.The destination of an incremental copy
|
359
|
+
# must either not exist, or must have been created with a previous incremental copy from the same source blob. Once created,
|
360
|
+
# the destination blob is permanently associated with the source and may only be used for incremental copies. The Get Blob
|
361
|
+
# Properties and List Blobs APIs indicate whether the blob is an incremental copy blob created in this way. Incremental
|
362
|
+
# copy blobs may not be downloaded directly. The only supported operations are Get Blob Properties, Incremental Copy Blob,
|
363
|
+
# and Delete Blob. The copied snapshots may be read and deleted as usual.
|
364
|
+
#
|
365
|
+
# ==== Attributes
|
366
|
+
#
|
367
|
+
# * +destination_container+ - String. The destination container name to copy to.
|
368
|
+
# * +destination_blob+ - String. The destination blob name to copy to.
|
369
|
+
# * +source_uri+ - String. Specifies the URI of the source page blob snapshot.
|
370
|
+
# This value is a URL of up to 2 KB in length that specifies a page blob snapshot. The
|
371
|
+
# value should be URL-encoded as it would appear in a request URI. The source blob must
|
372
|
+
# either be public or must be authenticated via a shared access signature. Here is an
|
373
|
+
# example of a source blob URL:
|
374
|
+
# https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot=<DateTime>
|
375
|
+
# * +options+ - Hash. Optional parameters.
|
376
|
+
#
|
377
|
+
# ==== Options
|
378
|
+
#
|
379
|
+
# Accepted key/value pairs in options parameter are:
|
380
|
+
# * +:metadata+ - Hash. Custom metadata values to store with the copy. If this parameter is not
|
381
|
+
# specified, the operation will copy the source blob metadata to the destination
|
382
|
+
# blob. If this parameter is specified, the destination blob is created with the
|
383
|
+
# specified metadata, and metadata is not copied from the source blob.
|
384
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to copy the blob only if the
|
385
|
+
# destination blob has been modified since the specified date/time. If the destination blob
|
386
|
+
# has not been modified, the Blob service returns status code 412 (Precondition Failed).
|
387
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to copy the blob only if the
|
388
|
+
# destination blob has not been modified since the specified date/time. If the destination
|
389
|
+
# blob has been modified, the Blob service returns status code 412 (Precondition Failed).
|
390
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to copy the blob
|
391
|
+
# only if the specified ETag value matches the ETag value for an existing destination blob.
|
392
|
+
# If the ETag for the destination blob does not match the ETag specified for If-Match,
|
393
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
394
|
+
# * +:if_none_match+ - String. An ETag value, or the wildcard character (*). Specify an ETag value for this
|
395
|
+
# conditional header to copy the blob only if the specified ETag value does not match the
|
396
|
+
# ETag value for the destination blob. Specify the wildcard character (*) to perform the
|
397
|
+
# operation only if the destination blob does not exist. If the specified condition isn't met,
|
398
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
399
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
400
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
401
|
+
# in the analytics logs when storage analytics logging is enabled.
|
402
|
+
# * +:lease_id+ - String. If this header is specified, the operation will be performed only if both of the
|
403
|
+
# following conditions are met:
|
404
|
+
# - The blob's lease is currently active.
|
405
|
+
# - The lease ID specified in the request matches that of the blob.
|
406
|
+
# If this header is specified and both of these conditions are not met, the request will fail
|
407
|
+
# and the Snapshot Blob operation will fail with status code 412 (Precondition Failed).
|
408
|
+
#
|
409
|
+
# See https://docs.microsoft.com/en-us/rest/api/storageservices/incremental-copy-blob
|
410
|
+
#
|
411
|
+
# Returns a tuple of (copy_id, copy_status).
|
412
|
+
#
|
413
|
+
# * +copy_id+ - String. String identifier for this copy operation. Use with Get Blob Properties to check
|
414
|
+
# the status of this copy operation, or pass to Abort Copy Blob to abort a pending copy.
|
415
|
+
# * +copy_status+ - String. State of the copy operation. This is always pending to indicate that the copy has
|
416
|
+
# started and is in progress.
|
417
|
+
#
|
418
|
+
def incremental_copy_blob(destination_container, destination_blob, source_uri, options = {})
|
419
|
+
# query parameters
|
420
|
+
query = { Azure::Storage::Common::QueryStringConstants::COMP => Azure::Storage::Common::QueryStringConstants::INCREMENTAL_COPY }
|
421
|
+
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
422
|
+
|
423
|
+
# URI
|
424
|
+
uri = blob_uri(destination_container, destination_blob, query)
|
425
|
+
|
426
|
+
# headers
|
427
|
+
headers = {}
|
428
|
+
StorageService.with_header headers, "x-ms-copy-source", source_uri
|
429
|
+
unless options.empty?
|
430
|
+
add_blob_conditional_headers options, headers
|
431
|
+
StorageService.add_metadata_to_headers options[:metadata], headers
|
432
|
+
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
433
|
+
end
|
434
|
+
|
435
|
+
response = call(:put, uri, nil, headers, options)
|
436
|
+
return response.headers["x-ms-copy-id"], response.headers["x-ms-copy-status"]
|
437
|
+
end
|
438
|
+
|
439
|
+
# Public: Sets a page blob's sequence number.
|
440
|
+
#
|
441
|
+
# ==== Attributes
|
442
|
+
#
|
443
|
+
# * +container+ - String. The container name.
|
444
|
+
# * +blob+ - String. The blob name.
|
445
|
+
# * +action+ - Symbol. Indicates how the service should modify the sequence
|
446
|
+
# number for the blob. Required if :sequence_number is used. This property
|
447
|
+
# applies to page blobs only.
|
448
|
+
#
|
449
|
+
# Specify one of the following options for this property:
|
450
|
+
#
|
451
|
+
# * +:max+ - Sets the sequence number to be the higher of the value included with
|
452
|
+
# the request and the value currently stored for the blob.
|
453
|
+
# * +:update+ - Sets the sequence number to the value included with the request.
|
454
|
+
# * +:increment+ - Increments the value of the sequence number by 1. If specifying this
|
455
|
+
# option, do not include the sequence_number option; doing so will return
|
456
|
+
# status code 400 (Bad Request).
|
457
|
+
#
|
458
|
+
# * +number+ - Integer. Sets the blob's sequence number. The sequence number is a
|
459
|
+
# user-controlled property that you can use to track requests and manage concurrency
|
460
|
+
# issues. Required if the 'action' parameter is set to :max or :update.
|
461
|
+
# This property applies to page blobs only.
|
462
|
+
#
|
463
|
+
# Use this together with the 'action' parameter to update the blob's sequence
|
464
|
+
# number, either to the specified value or to the higher of the values specified with
|
465
|
+
# the request or currently stored with the blob.
|
466
|
+
#
|
467
|
+
# This header should not be specified if the 'action' parameter is set to :increment;
|
468
|
+
# in this case the service automatically increments the sequence number by one.
|
469
|
+
#
|
470
|
+
# To set the sequence number to a value of your choosing, this property must be specified
|
471
|
+
# together with the 'action' parameter
|
472
|
+
# * +options+ - Hash. Optional parameters.
|
473
|
+
#
|
474
|
+
# ==== Options
|
475
|
+
#
|
476
|
+
# Accepted key/value pairs in options parameter are:
|
477
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
478
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
479
|
+
# in the analytics logs when storage analytics logging is enabled.
|
480
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
|
481
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
482
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
483
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to set the blob properties
|
484
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
485
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
486
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
|
487
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
488
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
489
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to set the blob properties
|
490
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
491
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
492
|
+
#
|
493
|
+
# See http://msdn.microsoft.com/en-us/library/azure/ee691966.aspx
|
494
|
+
#
|
495
|
+
# Returns nil on success.
|
496
|
+
def set_sequence_number(container, blob, action, number, options = {})
|
497
|
+
options = { sequence_number_action: action, sequence_number: number }.merge(options)
|
498
|
+
set_blob_properties container, blob, options
|
499
|
+
end
|
500
|
+
|
501
|
+
# Public: Creates a new page blob filled with given content.
|
502
|
+
#
|
503
|
+
# ==== Attributes
|
504
|
+
#
|
505
|
+
# * +container+ - String. The container name.
|
506
|
+
# * +blob+ - String. The blob name.
|
507
|
+
# * +length+ - Integer. Specifies the maximum size for the page blob, up to 1 TB.
|
508
|
+
# The page blob size must be aligned to a 512-byte boundary.
|
509
|
+
# * +content+ - String or IO. The content to put in the page blob.
|
510
|
+
# * +options+ - Hash. Optional parameters.
|
511
|
+
#
|
512
|
+
# ==== Options
|
513
|
+
#
|
514
|
+
# Accepted key/value pairs in options parameter are:
|
515
|
+
# * +:content_type+ - String. Content type for the blob. Will be saved with blob.
|
516
|
+
# * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
|
517
|
+
# * +:content_language+ - String. Content language for the blob. Will be saved with blob.
|
518
|
+
# * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
|
519
|
+
# * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
|
520
|
+
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
521
|
+
# and also can be used to attach additional metadata
|
522
|
+
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
|
523
|
+
# * +:sequence_number+ - Integer. The sequence number is a user-controlled value that you can use to track requests.
|
524
|
+
# The value of the sequence number must be between 0 and 2^63 - 1.The default value is 0.
|
525
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
526
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
527
|
+
# in the analytics logs when storage analytics logging is enabled.
|
528
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
529
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
530
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
531
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
532
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
533
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
534
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
535
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
536
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
537
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
538
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
539
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
540
|
+
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
541
|
+
# specify the valid lease ID for this header.
|
542
|
+
#
|
543
|
+
# See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
|
544
|
+
#
|
545
|
+
# Returns a Blob
|
546
|
+
def create_page_blob_from_content(container, blob, length, content, options = {})
|
547
|
+
options[:content_type] = get_or_apply_content_type(content, options[:content_type])
|
548
|
+
create_page_blob(container, blob, length, options)
|
549
|
+
|
550
|
+
content = StringIO.new(content) if content.is_a? String
|
551
|
+
upload_count = (Float(length) / Float(BlobConstants::DEFAULT_WRITE_PAGE_SIZE_IN_BYTES)).ceil
|
552
|
+
|
553
|
+
for idx in 0...upload_count
|
554
|
+
start_range = idx * BlobConstants::DEFAULT_WRITE_PAGE_SIZE_IN_BYTES
|
555
|
+
end_range = start_range + BlobConstants::DEFAULT_WRITE_PAGE_SIZE_IN_BYTES - 1
|
556
|
+
end_range = (length - 1) if end_range > (length - 1)
|
557
|
+
put_blob_pages(container, blob, start_range, end_range, content.read(BlobConstants::DEFAULT_WRITE_PAGE_SIZE_IN_BYTES), lease_id: options[:lease_id])
|
558
|
+
end
|
559
|
+
|
560
|
+
get_properties_options = {}
|
561
|
+
get_properties_options[:lease_id] = options[:lease_id] if options[:lease_id]
|
562
|
+
# Get the blob properties
|
563
|
+
get_blob_properties(container, blob, get_properties_options)
|
564
|
+
end
|
565
|
+
end
|
566
|
+
end
|