in CustomScript/azure/storage/blobservice.py [0:0]
def put_page_blob_from_file(self, container_name, blob_name, stream, count,
content_encoding=None, content_language=None,
content_md5=None, cache_control=None,
x_ms_blob_content_type=None,
x_ms_blob_content_encoding=None,
x_ms_blob_content_language=None,
x_ms_blob_content_md5=None,
x_ms_blob_cache_control=None,
x_ms_meta_name_values=None,
x_ms_lease_id=None,
x_ms_blob_sequence_number=None,
progress_callback=None):
'''
Creates a new page blob from a file/stream, or updates the content of an
existing page blob, with automatic chunking and progress notifications.
container_name: Name of existing container.
blob_name: Name of blob to create or update.
stream: Opened file/stream to upload as the blob content.
count:
Number of bytes to read from the stream. This is required, a page
blob cannot be created if the count is unknown.
content_encoding:
Optional. Specifies which content encodings have been applied to
the blob. This value is returned to the client when the Get Blob
(REST API) operation is performed on the blob resource. The client
can use this value when returned to decode the blob content.
content_language:
Optional. Specifies the natural languages used by this resource.
content_md5:
Optional. An MD5 hash of the blob content. This hash is used to
verify the integrity of the blob during transport. When this header
is specified, the storage service checks the hash that has arrived
with the one that was sent. If the two hashes do not match, the
operation will fail with error code 400 (Bad Request).
cache_control:
Optional. The Blob service stores this value but does not use or
modify it.
x_ms_blob_content_type: Optional. Set the blob's content type.
x_ms_blob_content_encoding: Optional. Set the blob's content encoding.
x_ms_blob_content_language: Optional. Set the blob's content language.
x_ms_blob_content_md5: Optional. Set the blob's MD5 hash.
x_ms_blob_cache_control: Optional. Sets the blob's cache control.
x_ms_meta_name_values: A dict containing name, value for metadata.
x_ms_lease_id: Required if the blob has an active lease.
x_ms_blob_sequence_number:
Optional. Set for page blobs only. The sequence number is a
user-controlled value that you can use to track requests. The
value of the sequence number must be between 0 and 2^63 - 1. The
default value is 0.
progress_callback:
Callback for progress with signature function(current, total) where
current is the number of bytes transfered so far, and total is the
size of the blob, or None if the total size is unknown.
'''
_validate_not_none('container_name', container_name)
_validate_not_none('blob_name', blob_name)
_validate_not_none('stream', stream)
_validate_not_none('count', count)
if count < 0:
raise TypeError(_ERROR_VALUE_NEGATIVE.format('count'))
if count % _PAGE_SIZE != 0:
raise TypeError(_ERROR_PAGE_BLOB_SIZE_ALIGNMENT.format(count))
if progress_callback:
progress_callback(0, count)
self.put_blob(container_name,
blob_name,
b'',
'PageBlob',
content_encoding,
content_language,
content_md5,
cache_control,
x_ms_blob_content_type,
x_ms_blob_content_encoding,
x_ms_blob_content_language,
x_ms_blob_content_md5,
x_ms_blob_cache_control,
x_ms_meta_name_values,
x_ms_lease_id,
count,
x_ms_blob_sequence_number)
remain_bytes = count
page_start = 0
while True:
request_count = min(remain_bytes, self._BLOB_MAX_CHUNK_DATA_SIZE)
data = stream.read(request_count)
if data:
length = len(data)
remain_bytes = remain_bytes - length
page_end = page_start + length - 1
self.put_page(container_name,
blob_name,
data,
'bytes={0}-{1}'.format(page_start, page_end),
'update',
x_ms_lease_id=x_ms_lease_id)
page_start = page_start + length
if progress_callback:
progress_callback(page_start, count)
else:
break