|
33 | 33 | ) |
34 | 34 | from ._serialization import ( |
35 | 35 | _get_path, |
| 36 | + _validate_and_format_range_headers, |
36 | 37 | ) |
37 | 38 | from ._upload_chunking import ( |
38 | 39 | _AppendBlobChunkUploader, |
@@ -286,6 +287,125 @@ def append_block(self, container_name, blob_name, block, |
286 | 287 |
|
287 | 288 | return self._perform_request(request, _parse_append_block) |
288 | 289 |
|
| 290 | + def append_block_from_url(self, container_name, blob_name, copy_source_url, source_range_start=None, |
| 291 | + source_range_end=None, source_content_md5=None, source_if_modified_since=None, |
| 292 | + source_if_unmodified_since=None, source_if_match=None, |
| 293 | + source_if_none_match=None, maxsize_condition=None, |
| 294 | + appendpos_condition=None, lease_id=None, if_modified_since=None, |
| 295 | + if_unmodified_since=None, if_match=None, |
| 296 | + if_none_match=None, timeout=None): |
| 297 | + """ |
| 298 | + Creates a new block to be committed as part of a blob, where the contents are read from a source url. |
| 299 | +
|
| 300 | + :param str container_name: |
| 301 | + Name of existing container. |
| 302 | + :param str blob_name: |
| 303 | + Name of blob. |
| 304 | + :param str copy_source_url: |
| 305 | + The URL of the source data. It can point to any Azure Blob or File, that is either public or has a |
| 306 | + shared access signature attached. |
| 307 | + :param int source_range_start: |
| 308 | + This indicates the start of the range of bytes(inclusive) that has to be taken from the copy source. |
| 309 | + :param int source_range_end: |
| 310 | + This indicates the end of the range of bytes(inclusive) that has to be taken from the copy source. |
| 311 | + :param str source_content_md5: |
| 312 | + If given, the service will calculate the MD5 hash of the block content and compare against this value. |
| 313 | + :param datetime source_if_modified_since: |
| 314 | + A DateTime value. Azure expects the date value passed in to be UTC. |
| 315 | + If timezone is included, any non-UTC datetimes will be converted to UTC. |
| 316 | + If a date is passed in without timezone info, it is assumed to be UTC. |
| 317 | + Specify this header to perform the operation only |
| 318 | + if the source resource has been modified since the specified time. |
| 319 | + :param datetime source_if_unmodified_since: |
| 320 | + A DateTime value. Azure expects the date value passed in to be UTC. |
| 321 | + If timezone is included, any non-UTC datetimes will be converted to UTC. |
| 322 | + If a date is passed in without timezone info, it is assumed to be UTC. |
| 323 | + Specify this header to perform the operation only if |
| 324 | + the source resource has not been modified since the specified date/time. |
| 325 | + :param str source_if_match: |
| 326 | + An ETag value, or the wildcard character (*). Specify this header to perform |
| 327 | + the operation only if the source resource's ETag matches the value specified. |
| 328 | + :param str source_if_none_match: |
| 329 | + An ETag value, or the wildcard character (*). Specify this header |
| 330 | + to perform the operation only if the source resource's ETag does not match |
| 331 | + the value specified. Specify the wildcard character (*) to perform |
| 332 | + the operation only if the source resource does not exist, and fail the |
| 333 | + operation if it does exist. |
| 334 | + :param int maxsize_condition: |
| 335 | + Optional conditional header. The max length in bytes permitted for |
| 336 | + the append blob. If the Append Block operation would cause the blob |
| 337 | + to exceed that limit or if the blob size is already greater than the |
| 338 | + value specified in this header, the request will fail with |
| 339 | + MaxBlobSizeConditionNotMet error (HTTP status code 412 - Precondition Failed). |
| 340 | + :param int appendpos_condition: |
| 341 | + Optional conditional header, used only for the Append Block operation. |
| 342 | + A number indicating the byte offset to compare. Append Block will |
| 343 | + succeed only if the append position is equal to this number. If it |
| 344 | + is not, the request will fail with the |
| 345 | + AppendPositionConditionNotMet error |
| 346 | + (HTTP status code 412 - Precondition Failed). |
| 347 | + :param str lease_id: |
| 348 | + Required if the blob has an active lease. |
| 349 | + :param datetime if_modified_since: |
| 350 | + A DateTime value. Azure expects the date value passed in to be UTC. |
| 351 | + If timezone is included, any non-UTC datetimes will be converted to UTC. |
| 352 | + If a date is passed in without timezone info, it is assumed to be UTC. |
| 353 | + Specify this header to perform the operation only |
| 354 | + if the resource has been modified since the specified time. |
| 355 | + :param datetime if_unmodified_since: |
| 356 | + A DateTime value. Azure expects the date value passed in to be UTC. |
| 357 | + If timezone is included, any non-UTC datetimes will be converted to UTC. |
| 358 | + If a date is passed in without timezone info, it is assumed to be UTC. |
| 359 | + Specify this header to perform the operation only if |
| 360 | + the resource has not been modified since the specified date/time. |
| 361 | + :param str if_match: |
| 362 | + An ETag value, or the wildcard character (*). Specify this header to perform |
| 363 | + the operation only if the resource's ETag matches the value specified. |
| 364 | + :param str if_none_match: |
| 365 | + An ETag value, or the wildcard character (*). Specify this header |
| 366 | + to perform the operation only if the resource's ETag does not match |
| 367 | + the value specified. Specify the wildcard character (*) to perform |
| 368 | + the operation only if the resource does not exist, and fail the |
| 369 | + operation if it does exist. |
| 370 | + :param int timeout: |
| 371 | + The timeout parameter is expressed in seconds. |
| 372 | + """ |
| 373 | + _validate_encryption_unsupported(self.require_encryption, self.key_encryption_key) |
| 374 | + _validate_not_none('container_name', container_name) |
| 375 | + _validate_not_none('blob_name', blob_name) |
| 376 | + _validate_not_none('copy_source_url', copy_source_url) |
| 377 | + |
| 378 | + request = HTTPRequest() |
| 379 | + request.method = 'PUT' |
| 380 | + request.host_locations = self._get_host_locations() |
| 381 | + request.path = _get_path(container_name, blob_name) |
| 382 | + request.query = { |
| 383 | + 'comp': 'appendblock', |
| 384 | + 'timeout': _int_to_str(timeout), |
| 385 | + } |
| 386 | + request.headers = { |
| 387 | + 'x-ms-copy-source': copy_source_url, |
| 388 | + 'x-ms-source-content-md5': source_content_md5, |
| 389 | + 'x-ms-source-if-Modified-Since': _datetime_to_utc_string(source_if_modified_since), |
| 390 | + 'x-ms-source-if-Unmodified-Since': _datetime_to_utc_string(source_if_unmodified_since), |
| 391 | + 'x-ms-source-if-Match': _to_str(source_if_match), |
| 392 | + 'x-ms-source-if-None-Match': _to_str(source_if_none_match), |
| 393 | + 'x-ms-blob-condition-maxsize': _to_str(maxsize_condition), |
| 394 | + 'x-ms-blob-condition-appendpos': _to_str(appendpos_condition), |
| 395 | + 'x-ms-lease-id': _to_str(lease_id), |
| 396 | + 'If-Modified-Since': _datetime_to_utc_string(if_modified_since), |
| 397 | + 'If-Unmodified-Since': _datetime_to_utc_string(if_unmodified_since), |
| 398 | + 'If-Match': _to_str(if_match), |
| 399 | + 'If-None-Match': _to_str(if_none_match) |
| 400 | + } |
| 401 | + |
| 402 | + _validate_and_format_range_headers(request, source_range_start, source_range_end, |
| 403 | + start_range_required=False, |
| 404 | + end_range_required=False, |
| 405 | + range_header_name="x-ms-source-range") |
| 406 | + |
| 407 | + return self._perform_request(request, _parse_append_block) |
| 408 | + |
289 | 409 | # ----Convenience APIs---------------------------------------------- |
290 | 410 |
|
291 | 411 | def append_blob_from_path( |
|
0 commit comments