azure-storage-blob 1.1.0 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- 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 -932
- data/lib/azure/storage/blob/blob_service.rb +720 -679
- 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 +15 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1450a2bef8b99c5aaf74848e8720523a89b15c0d6b0edee6940196486dc1e952
|
4
|
+
data.tar.gz: 338c9ecf38a8a2a5bb938fcee0b9d31e0546c7f097802ac365a50e9759765b5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b94f26133f08913397eff90b0bcb98b6d98e00deba59bf0ee2e5de0d63a41a6a53c3b33445ba78e27881ad2b4539b58576c82e26586fe3d77e68b820ea755a37
|
7
|
+
data.tar.gz: c85c12bd39308170140511294976a0a633bc246dd18f17efad7b884a2dcd0f5ae90fd5fd635e8a9d5ed87c8187808eef64e7f5d0851f96e1894d35e7872a6c80
|
@@ -1,244 +1,244 @@
|
|
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
|
-
|
27
|
-
module Azure::Storage
|
28
|
-
module Blob
|
29
|
-
# Public: Creates a new append blob. Note that calling create_append_blob to create an append
|
30
|
-
# blob only initializes the blob. To add content to an append blob, call append_blob_blocks method.
|
31
|
-
#
|
32
|
-
# ==== Attributes
|
33
|
-
#
|
34
|
-
# * +container+ - String. The container name.
|
35
|
-
# * +blob+ - String. The blob name.
|
36
|
-
# * +options+ - Hash. Optional parameters.
|
37
|
-
#
|
38
|
-
# ==== Options
|
39
|
-
#
|
40
|
-
# Accepted key/value pairs in options parameter are:
|
41
|
-
# * +:content_type+ - String. Content type for the blob. Will be saved with blob.
|
42
|
-
# * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
|
43
|
-
# * +:content_language+ - String. Content language for the blob. Will be saved with blob.
|
44
|
-
# * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
|
45
|
-
# * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
|
46
|
-
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
47
|
-
# and also can be used to attach additional metadata
|
48
|
-
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
|
49
|
-
# * +:timeout+ - Integer. A timeout in seconds.
|
50
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
51
|
-
# in the analytics logs when storage analytics logging is enabled.
|
52
|
-
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
53
|
-
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
54
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
55
|
-
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
56
|
-
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
57
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
58
|
-
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
59
|
-
# only if the blob's ETag value matches the value specified. If the values do not match,
|
60
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
61
|
-
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
62
|
-
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
63
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
64
|
-
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
65
|
-
# specify the valid lease ID for this header.
|
66
|
-
#
|
67
|
-
# See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
|
68
|
-
#
|
69
|
-
# Returns a Blob
|
70
|
-
def create_append_blob(container, blob, options = {})
|
71
|
-
query = {}
|
72
|
-
StorageService.with_query query, "timeout", options[:timeout] if options[:timeout]
|
73
|
-
|
74
|
-
uri = blob_uri(container, blob, query)
|
75
|
-
|
76
|
-
headers = {}
|
77
|
-
|
78
|
-
# set x-ms-blob-type to AppendBlob
|
79
|
-
StorageService.with_header headers, "x-ms-blob-type", "AppendBlob"
|
80
|
-
|
81
|
-
# ensure content-length is 0
|
82
|
-
StorageService.with_header headers, "Content-Length", 0
|
83
|
-
|
84
|
-
# set the rest of the optional headers
|
85
|
-
StorageService.with_header headers, "x-ms-blob-content-type", options[:content_type]
|
86
|
-
StorageService.with_header headers, "x-ms-blob-content-encoding", options[:content_encoding]
|
87
|
-
StorageService.with_header headers, "x-ms-blob-content-language", options[:content_language]
|
88
|
-
StorageService.with_header headers, "x-ms-blob-content-md5", options[:content_md5]
|
89
|
-
StorageService.with_header headers, "x-ms-blob-cache-control", options[:cache_control]
|
90
|
-
StorageService.with_header headers, "x-ms-blob-content-disposition", options[:content_disposition]
|
91
|
-
|
92
|
-
StorageService.add_metadata_to_headers options[:metadata], headers
|
93
|
-
add_blob_conditional_headers options, headers
|
94
|
-
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
95
|
-
headers["x-ms-blob-content-type"] = Default::CONTENT_TYPE_VALUE unless headers["x-ms-blob-content-type"]
|
96
|
-
|
97
|
-
# call PutBlob with empty body
|
98
|
-
response = call(:put, uri, nil, headers, options)
|
99
|
-
|
100
|
-
result = Serialization.blob_from_headers(response.headers)
|
101
|
-
result.name = blob
|
102
|
-
result.metadata = options[:metadata] if options[:metadata]
|
103
|
-
|
104
|
-
result
|
105
|
-
end
|
106
|
-
|
107
|
-
# Public: Commits a new block of data to the end of an existing append blob.
|
108
|
-
# This operation is permitted only on blobs created with the create_append_blob API.
|
109
|
-
#
|
110
|
-
# ==== Attributes
|
111
|
-
#
|
112
|
-
# * +container+ - String. The container name.
|
113
|
-
# * +blob+ - String. The blob name.
|
114
|
-
# * +content+ - IO or String. The content of the blob.
|
115
|
-
# * +options+ - Hash. Optional parameters.
|
116
|
-
#
|
117
|
-
# ==== Options
|
118
|
-
#
|
119
|
-
# Accepted key/value pairs in options parameter are:
|
120
|
-
# * +:content_md5+ - String. Content MD5 for the request contents.
|
121
|
-
# * +:max_size+ - Integer. The max length in bytes permitted for the append blob
|
122
|
-
# * +:append_position+ - Integer. A number indicating the byte offset to compare. It will succeed only if the append position is equal to this number
|
123
|
-
# * +:timeout+ - Integer. A timeout in seconds.
|
124
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
125
|
-
# in the analytics logs when storage analytics logging is enabled.
|
126
|
-
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to append a block only if
|
127
|
-
# the blob has been modified since the specified date/time. If the blob has not been modified,
|
128
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
129
|
-
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to append a block only if
|
130
|
-
# the blob has not been modified since the specified date/time. If the blob has been modified,
|
131
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
132
|
-
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to append a block only if
|
133
|
-
# the blob's ETag value matches the value specified. If the values do not match,
|
134
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
135
|
-
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to append a block only if
|
136
|
-
# the blob's ETag value does not match the value specified. If the values are identical,
|
137
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
138
|
-
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an
|
139
|
-
# active lease, specify the valid lease ID for this header.
|
140
|
-
#
|
141
|
-
# See http://msdn.microsoft.com/en-us/library/azure/mt427365.aspx
|
142
|
-
#
|
143
|
-
# Returns a Blob
|
144
|
-
def append_blob_block(container, blob, content, options = {})
|
145
|
-
query = { "comp" => "appendblock" }
|
146
|
-
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
147
|
-
|
148
|
-
uri = blob_uri(container, blob, query)
|
149
|
-
|
150
|
-
headers = {}
|
151
|
-
StorageService.with_header headers, "Content-MD5", options[:content_md5]
|
152
|
-
StorageService.with_header headers, "x-ms-lease-id", options[:lease_id]
|
153
|
-
StorageService.with_header headers, "x-ms-blob-condition-maxsize", options[:max_size]
|
154
|
-
StorageService.with_header headers, "x-ms-blob-condition-appendpos", options[:append_position]
|
155
|
-
|
156
|
-
add_blob_conditional_headers options, headers
|
157
|
-
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
158
|
-
|
159
|
-
response = call(:put, uri, content, headers, options)
|
160
|
-
result = Serialization.blob_from_headers(response.headers)
|
161
|
-
result.name = blob
|
162
|
-
|
163
|
-
result
|
164
|
-
end
|
165
|
-
|
166
|
-
# Public: Creates a new append blob with given content
|
167
|
-
#
|
168
|
-
# ==== Attributes
|
169
|
-
#
|
170
|
-
# * +container+ - String. The container name.
|
171
|
-
# * +blob+ - String. The blob name.
|
172
|
-
# * +content+ - IO or String. Content to write.
|
173
|
-
# * +options+ - Hash. Optional parameters.
|
174
|
-
#
|
175
|
-
# ==== Options
|
176
|
-
#
|
177
|
-
# Accepted key/value pairs in options parameter are:
|
178
|
-
# * +:content_type+ - String. Content type for the blob. Will be saved with blob.
|
179
|
-
# * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
|
180
|
-
# * +:content_language+ - String. Content language for the blob. Will be saved with blob.
|
181
|
-
# * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
|
182
|
-
# * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
|
183
|
-
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
184
|
-
# and also can be used to attach additional metadata
|
185
|
-
# * +:max_size+ - Integer. The max length in bytes permitted for the append blob.
|
186
|
-
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
|
187
|
-
# * +:timeout+ - Integer. A timeout in seconds.
|
188
|
-
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
189
|
-
# in the analytics logs when storage analytics logging is enabled.
|
190
|
-
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
191
|
-
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
192
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
193
|
-
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
194
|
-
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
195
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
196
|
-
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
197
|
-
# only if the blob's ETag value matches the value specified. If the values do not match,
|
198
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
199
|
-
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
200
|
-
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
201
|
-
# the Blob service returns status code 412 (Precondition Failed).
|
202
|
-
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
203
|
-
# specify the valid lease ID for this header.
|
204
|
-
#
|
205
|
-
# See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
|
206
|
-
#
|
207
|
-
# Returns a Blob
|
208
|
-
def create_append_blob_from_content(container, blob, content, options = {})
|
209
|
-
# Fail fast if content has larger size than max_size
|
210
|
-
max_size = options.delete :max_size
|
211
|
-
if max_size
|
212
|
-
if content.respond_to?(:size) && max_size < content.size
|
213
|
-
raise Azure::Storage::Common::Core::StorageError.new("Given content has exceeded the specified maximum size for the blob.")
|
214
|
-
end
|
215
|
-
end
|
216
|
-
options[:content_type] = get_or_apply_content_type(content, options[:content_type])
|
217
|
-
create_append_blob(container, blob, options)
|
218
|
-
content = StringIO.new(content) if content.is_a? String
|
219
|
-
# initialize the append block options.
|
220
|
-
append_block_options = {}
|
221
|
-
append_block_options[:if_modified_since] = options[:if_modified_since] if options[:if_modified_since]
|
222
|
-
append_block_options[:if_unmodified_since] = options[:if_unmodified_since] if options[:if_unmodified_since]
|
223
|
-
append_block_options[:if_match] = options[:if_match] if options[:if_match]
|
224
|
-
append_block_options[:if_none_match] = options[:if_none_match] if options[:if_none_match]
|
225
|
-
append_block_options[:lease_id] = options[:lease_id] if options[:lease_id]
|
226
|
-
append_block_options[:max_size] = max_size if max_size
|
227
|
-
position = 0
|
228
|
-
while !content.eof?
|
229
|
-
payload = content.read(BlobConstants::DEFAULT_WRITE_BLOCK_SIZE_IN_BYTES)
|
230
|
-
# set the append position to make sure that each append is going to the correct offset.
|
231
|
-
append_block_options[:append_position] = position
|
232
|
-
append_blob_block(container, blob, payload, append_block_options)
|
233
|
-
# calculate the position after the append.
|
234
|
-
position += payload.size
|
235
|
-
end
|
236
|
-
|
237
|
-
get_properties_options = {}
|
238
|
-
get_properties_options[:lease_id] = options[:lease_id] if options[:lease_id]
|
239
|
-
|
240
|
-
# Get the blob properties
|
241
|
-
get_blob_properties(container, blob, get_properties_options)
|
242
|
-
end
|
243
|
-
end
|
244
|
-
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
|
+
|
27
|
+
module Azure::Storage
|
28
|
+
module Blob
|
29
|
+
# Public: Creates a new append blob. Note that calling create_append_blob to create an append
|
30
|
+
# blob only initializes the blob. To add content to an append blob, call append_blob_blocks method.
|
31
|
+
#
|
32
|
+
# ==== Attributes
|
33
|
+
#
|
34
|
+
# * +container+ - String. The container name.
|
35
|
+
# * +blob+ - String. The blob name.
|
36
|
+
# * +options+ - Hash. Optional parameters.
|
37
|
+
#
|
38
|
+
# ==== Options
|
39
|
+
#
|
40
|
+
# Accepted key/value pairs in options parameter are:
|
41
|
+
# * +:content_type+ - String. Content type for the blob. Will be saved with blob.
|
42
|
+
# * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
|
43
|
+
# * +:content_language+ - String. Content language for the blob. Will be saved with blob.
|
44
|
+
# * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
|
45
|
+
# * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
|
46
|
+
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
47
|
+
# and also can be used to attach additional metadata
|
48
|
+
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
|
49
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
50
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
51
|
+
# in the analytics logs when storage analytics logging is enabled.
|
52
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
53
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
54
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
55
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
56
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
57
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
58
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
59
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
60
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
61
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
62
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
63
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
64
|
+
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
65
|
+
# specify the valid lease ID for this header.
|
66
|
+
#
|
67
|
+
# See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
|
68
|
+
#
|
69
|
+
# Returns a Blob
|
70
|
+
def create_append_blob(container, blob, options = {})
|
71
|
+
query = {}
|
72
|
+
StorageService.with_query query, "timeout", options[:timeout] if options[:timeout]
|
73
|
+
|
74
|
+
uri = blob_uri(container, blob, query)
|
75
|
+
|
76
|
+
headers = {}
|
77
|
+
|
78
|
+
# set x-ms-blob-type to AppendBlob
|
79
|
+
StorageService.with_header headers, "x-ms-blob-type", "AppendBlob"
|
80
|
+
|
81
|
+
# ensure content-length is 0
|
82
|
+
StorageService.with_header headers, "Content-Length", 0
|
83
|
+
|
84
|
+
# set the rest of the optional headers
|
85
|
+
StorageService.with_header headers, "x-ms-blob-content-type", options[:content_type]
|
86
|
+
StorageService.with_header headers, "x-ms-blob-content-encoding", options[:content_encoding]
|
87
|
+
StorageService.with_header headers, "x-ms-blob-content-language", options[:content_language]
|
88
|
+
StorageService.with_header headers, "x-ms-blob-content-md5", options[:content_md5]
|
89
|
+
StorageService.with_header headers, "x-ms-blob-cache-control", options[:cache_control]
|
90
|
+
StorageService.with_header headers, "x-ms-blob-content-disposition", options[:content_disposition]
|
91
|
+
|
92
|
+
StorageService.add_metadata_to_headers options[:metadata], headers
|
93
|
+
add_blob_conditional_headers options, headers
|
94
|
+
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
95
|
+
headers["x-ms-blob-content-type"] = Default::CONTENT_TYPE_VALUE unless headers["x-ms-blob-content-type"]
|
96
|
+
|
97
|
+
# call PutBlob with empty body
|
98
|
+
response = call(:put, uri, nil, headers, options)
|
99
|
+
|
100
|
+
result = Serialization.blob_from_headers(response.headers)
|
101
|
+
result.name = blob
|
102
|
+
result.metadata = options[:metadata] if options[:metadata]
|
103
|
+
|
104
|
+
result
|
105
|
+
end
|
106
|
+
|
107
|
+
# Public: Commits a new block of data to the end of an existing append blob.
|
108
|
+
# This operation is permitted only on blobs created with the create_append_blob API.
|
109
|
+
#
|
110
|
+
# ==== Attributes
|
111
|
+
#
|
112
|
+
# * +container+ - String. The container name.
|
113
|
+
# * +blob+ - String. The blob name.
|
114
|
+
# * +content+ - IO or String. The content of the blob.
|
115
|
+
# * +options+ - Hash. Optional parameters.
|
116
|
+
#
|
117
|
+
# ==== Options
|
118
|
+
#
|
119
|
+
# Accepted key/value pairs in options parameter are:
|
120
|
+
# * +:content_md5+ - String. Content MD5 for the request contents.
|
121
|
+
# * +:max_size+ - Integer. The max length in bytes permitted for the append blob
|
122
|
+
# * +:append_position+ - Integer. A number indicating the byte offset to compare. It will succeed only if the append position is equal to this number
|
123
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
124
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
125
|
+
# in the analytics logs when storage analytics logging is enabled.
|
126
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to append a block only if
|
127
|
+
# the blob has been modified since the specified date/time. If the blob has not been modified,
|
128
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
129
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to append a block only if
|
130
|
+
# the blob has not been modified since the specified date/time. If the blob has been modified,
|
131
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
132
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to append a block only if
|
133
|
+
# the blob's ETag value matches the value specified. If the values do not match,
|
134
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
135
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to append a block only if
|
136
|
+
# the blob's ETag value does not match the value specified. If the values are identical,
|
137
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
138
|
+
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an
|
139
|
+
# active lease, specify the valid lease ID for this header.
|
140
|
+
#
|
141
|
+
# See http://msdn.microsoft.com/en-us/library/azure/mt427365.aspx
|
142
|
+
#
|
143
|
+
# Returns a Blob
|
144
|
+
def append_blob_block(container, blob, content, options = {})
|
145
|
+
query = { "comp" => "appendblock" }
|
146
|
+
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
147
|
+
|
148
|
+
uri = blob_uri(container, blob, query)
|
149
|
+
|
150
|
+
headers = {}
|
151
|
+
StorageService.with_header headers, "Content-MD5", options[:content_md5]
|
152
|
+
StorageService.with_header headers, "x-ms-lease-id", options[:lease_id]
|
153
|
+
StorageService.with_header headers, "x-ms-blob-condition-maxsize", options[:max_size]
|
154
|
+
StorageService.with_header headers, "x-ms-blob-condition-appendpos", options[:append_position]
|
155
|
+
|
156
|
+
add_blob_conditional_headers options, headers
|
157
|
+
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
158
|
+
|
159
|
+
response = call(:put, uri, content, headers, options)
|
160
|
+
result = Serialization.blob_from_headers(response.headers)
|
161
|
+
result.name = blob
|
162
|
+
|
163
|
+
result
|
164
|
+
end
|
165
|
+
|
166
|
+
# Public: Creates a new append blob with given content
|
167
|
+
#
|
168
|
+
# ==== Attributes
|
169
|
+
#
|
170
|
+
# * +container+ - String. The container name.
|
171
|
+
# * +blob+ - String. The blob name.
|
172
|
+
# * +content+ - IO or String. Content to write.
|
173
|
+
# * +options+ - Hash. Optional parameters.
|
174
|
+
#
|
175
|
+
# ==== Options
|
176
|
+
#
|
177
|
+
# Accepted key/value pairs in options parameter are:
|
178
|
+
# * +:content_type+ - String. Content type for the blob. Will be saved with blob.
|
179
|
+
# * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
|
180
|
+
# * +:content_language+ - String. Content language for the blob. Will be saved with blob.
|
181
|
+
# * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
|
182
|
+
# * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
|
183
|
+
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
184
|
+
# and also can be used to attach additional metadata
|
185
|
+
# * +:max_size+ - Integer. The max length in bytes permitted for the append blob.
|
186
|
+
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
|
187
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
188
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
189
|
+
# in the analytics logs when storage analytics logging is enabled.
|
190
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
191
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
192
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
193
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
194
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
195
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
196
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
197
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
198
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
199
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
200
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
201
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
202
|
+
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
203
|
+
# specify the valid lease ID for this header.
|
204
|
+
#
|
205
|
+
# See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
|
206
|
+
#
|
207
|
+
# Returns a Blob
|
208
|
+
def create_append_blob_from_content(container, blob, content, options = {})
|
209
|
+
# Fail fast if content has larger size than max_size
|
210
|
+
max_size = options.delete :max_size
|
211
|
+
if max_size
|
212
|
+
if content.respond_to?(:size) && max_size < content.size
|
213
|
+
raise Azure::Storage::Common::Core::StorageError.new("Given content has exceeded the specified maximum size for the blob.")
|
214
|
+
end
|
215
|
+
end
|
216
|
+
options[:content_type] = get_or_apply_content_type(content, options[:content_type])
|
217
|
+
create_append_blob(container, blob, options)
|
218
|
+
content = StringIO.new(content) if content.is_a? String
|
219
|
+
# initialize the append block options.
|
220
|
+
append_block_options = {}
|
221
|
+
append_block_options[:if_modified_since] = options[:if_modified_since] if options[:if_modified_since]
|
222
|
+
append_block_options[:if_unmodified_since] = options[:if_unmodified_since] if options[:if_unmodified_since]
|
223
|
+
append_block_options[:if_match] = options[:if_match] if options[:if_match]
|
224
|
+
append_block_options[:if_none_match] = options[:if_none_match] if options[:if_none_match]
|
225
|
+
append_block_options[:lease_id] = options[:lease_id] if options[:lease_id]
|
226
|
+
append_block_options[:max_size] = max_size if max_size
|
227
|
+
position = 0
|
228
|
+
while !content.eof?
|
229
|
+
payload = content.read(BlobConstants::DEFAULT_WRITE_BLOCK_SIZE_IN_BYTES)
|
230
|
+
# set the append position to make sure that each append is going to the correct offset.
|
231
|
+
append_block_options[:append_position] = position
|
232
|
+
append_blob_block(container, blob, payload, append_block_options)
|
233
|
+
# calculate the position after the append.
|
234
|
+
position += payload.size
|
235
|
+
end
|
236
|
+
|
237
|
+
get_properties_options = {}
|
238
|
+
get_properties_options[:lease_id] = options[:lease_id] if options[:lease_id]
|
239
|
+
|
240
|
+
# Get the blob properties
|
241
|
+
get_blob_properties(container, blob, get_properties_options)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
@@ -1,47 +1,47 @@
|
|
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
|
-
|
27
|
-
require "rubygems"
|
28
|
-
require "nokogiri"
|
29
|
-
require "base64"
|
30
|
-
|
31
|
-
require "azure/storage/common"
|
32
|
-
|
33
|
-
module Azure
|
34
|
-
module Storage
|
35
|
-
module Blob
|
36
|
-
autoload :Default, "azure/storage/blob/default"
|
37
|
-
autoload :Version, "azure/storage/blob/version"
|
38
|
-
autoload :Blob, "azure/storage/blob/blob"
|
39
|
-
autoload :Block, "azure/storage/blob/block"
|
40
|
-
autoload :Page, "azure/storage/blob/page"
|
41
|
-
autoload :Append, "azure/storage/blob/append"
|
42
|
-
autoload :Container, "azure/storage/blob/container"
|
43
|
-
autoload :Serialization, "azure/storage/blob/serialization"
|
44
|
-
autoload :BlobService, "azure/storage/blob/blob_service"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
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
|
+
|
27
|
+
require "rubygems"
|
28
|
+
require "nokogiri"
|
29
|
+
require "base64"
|
30
|
+
|
31
|
+
require "azure/storage/common"
|
32
|
+
|
33
|
+
module Azure
|
34
|
+
module Storage
|
35
|
+
module Blob
|
36
|
+
autoload :Default, "azure/storage/blob/default"
|
37
|
+
autoload :Version, "azure/storage/blob/version"
|
38
|
+
autoload :Blob, "azure/storage/blob/blob"
|
39
|
+
autoload :Block, "azure/storage/blob/block"
|
40
|
+
autoload :Page, "azure/storage/blob/page"
|
41
|
+
autoload :Append, "azure/storage/blob/append"
|
42
|
+
autoload :Container, "azure/storage/blob/container"
|
43
|
+
autoload :Serialization, "azure/storage/blob/serialization"
|
44
|
+
autoload :BlobService, "azure/storage/blob/blob_service"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|