in azure/multiapi/storage/v2015_04_05/blob/baseblobservice.py [0:0]
def copy_blob(self, container_name, blob_name, copy_source,
metadata=None,
source_if_modified_since=None,
source_if_unmodified_since=None,
source_if_match=None, source_if_none_match=None,
destination_if_modified_since=None,
destination_if_unmodified_since=None,
destination_if_match=None,
destination_if_none_match=None,
destination_lease_id=None,
source_lease_id=None, timeout=None):
'''
Copies a blob to a destination within the storage account.
The source for a Copy Blob operation can be a committed blob
or an Azure file in any Azure storage account.
:param str container_name:
Name of existing container.
:param str blob_name:
Name of existing blob.
:param str copy_source:
URL up to 2 KB in length that specifies a blob. A source blob in
the same account can be private, but a blob in another account
must be public or accept credentials included in this URL, such as
a Shared Access Signature. Examples:
https://myaccount.blob.core.windows.net/mycontainer/myblob
https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot=<DateTime>
:param metadata:
Dict containing name and value pairs.
:type metadata: A dict mapping str to str.
:param datetime source_if_modified_since:
A DateTime value. Azure expects the date value passed in to be UTC.
If timezone is included, any non-UTC datetimes will be converted to UTC.
If a date is passed in without timezone info, it is assumed to be UTC.
Specify this conditional header to copy the blob only if the source
blob has been modified since the specified date/time.
:param datetime source_if_unmodified_since:
A DateTime value. Azure expects the date value passed in to be UTC.
If timezone is included, any non-UTC datetimes will be converted to UTC.
If a date is passed in without timezone info, it is assumed to be UTC.
Specify this conditional header to copy the blob only if the source blob
has not been modified since the specified date/time.
:param ETag source_if_match:
An ETag value, or the wildcard character (*). Specify this conditional
header to copy the source blob only if its ETag matches the value
specified. If the ETag values do not match, the Blob service returns
status code 412 (Precondition Failed). This header cannot be specified
if the source is an Azure File.
:param ETag source_if_none_match:
An ETag value, or the wildcard character (*). Specify this conditional
header to copy the blob only if its ETag does not match the value
specified. If the values are identical, the Blob service returns status
code 412 (Precondition Failed). This header cannot be specified if the
source is an Azure File.
:param datetime destination_if_modified_since:
A DateTime value. Azure expects the date value passed in to be UTC.
If timezone is included, any non-UTC datetimes will be converted to UTC.
If a date is passed in without timezone info, it is assumed to be UTC.
Specify this conditional header to copy the blob only
if the destination blob has been modified since the specified date/time.
If the destination blob has not been modified, the Blob service returns
status code 412 (Precondition Failed).
:param datetime destination_if_unmodified_since:
A DateTime value. Azure expects the date value passed in to be UTC.
If timezone is included, any non-UTC datetimes will be converted to UTC.
If a date is passed in without timezone info, it is assumed to be UTC.
Specify this conditional header to copy the blob only
if the destination blob has not been modified since the specified
date/time. If the destination blob has been modified, the Blob service
returns status code 412 (Precondition Failed).
:param ETag destination_if_match:
An ETag value, or the wildcard character (*). Specify an ETag value for
this conditional header to copy the blob only if the specified ETag value
matches the ETag value for an existing destination blob. If the ETag for
the destination blob does not match the ETag specified for If-Match, the
Blob service returns status code 412 (Precondition Failed).
:param ETag destination_if_none_match:
An ETag value, or the wildcard character (*). Specify an ETag value for
this conditional header to copy the blob only if the specified ETag value
does not match the ETag value for the destination blob. Specify the wildcard
character (*) to perform the operation only if the destination blob does not
exist. If the specified condition isn't met, the Blob service returns status
code 412 (Precondition Failed).
:param str destination_lease_id:
The lease ID specified for this header must match the lease ID of the
destination blob. If the request does not include the lease ID or it is not
valid, the operation fails with status code 412 (Precondition Failed).
:param str source_lease_id:
Specify this to perform the Copy Blob operation only if
the lease ID given matches the active lease ID of the source blob.
:param int timeout:
The timeout parameter is expressed in seconds.
:return: Copy operation properties such as status, source, and ID.
:rtype: :class:`~azure.storage.blob.models.CopyProperties`
'''
_validate_not_none('container_name', container_name)
_validate_not_none('blob_name', blob_name)
_validate_not_none('copy_source', copy_source)
if copy_source.startswith('/'):
# Backwards compatibility for earlier versions of the SDK where
# the copy source can be in the following formats:
# - Blob in named container:
# /accountName/containerName/blobName
# - Snapshot in named container:
# /accountName/containerName/blobName?snapshot=<DateTime>
# - Blob in root container:
# /accountName/blobName
# - Snapshot in root container:
# /accountName/blobName?snapshot=<DateTime>
account, _, source =\
copy_source.partition('/')[2].partition('/')
copy_source = self.protocol + '://' + \
self.primary_endpoint + '/' + source
request = HTTPRequest()
request.method = 'PUT'
request.host = self._get_host()
request.path = _get_path(container_name, blob_name)
request.query = [('timeout', _int_to_str(timeout))]
request.headers = [
('x-ms-copy-source', _to_str(copy_source)),
('x-ms-meta-name-values', metadata),
('x-ms-source-if-modified-since',
_to_str(source_if_modified_since)),
('x-ms-source-if-unmodified-since',
_to_str(source_if_unmodified_since)),
('x-ms-source-if-match', _to_str(source_if_match)),
('x-ms-source-if-none-match',
_to_str(source_if_none_match)),
('If-Modified-Since', _datetime_to_utc_string(destination_if_modified_since)),
('If-Unmodified-Since', _datetime_to_utc_string(destination_if_unmodified_since)),
('If-Match', _to_str(destination_if_match)),
('If-None-Match', _to_str(destination_if_none_match)),
('x-ms-lease-id', _to_str(destination_lease_id)),
('x-ms-source-lease-id', _to_str(source_lease_id))
]
response = self._perform_request(request)
props = _parse_properties(response, BlobProperties)
return props.copy