[azure-storage-blob] BlobClient upload_blob does not use headers parameter for multi-block uploads.
See original GitHub issue- Package Name: azure-storage-blob
- Package Version: 12.4.0
- Operating System: WSL / Ubuntu 20.04.1 LTS / 4.19.104-microsoft-standard / Windows 10.0.19041.450
- Python Version: 3.8.2
Describe the bug
BlobClient
upload_blob()
does not inject the headers parameter if the upload takes the multi-block upload code path (single block upload works).
To Reproduce
The provided headers will not be injected into the request if the object size exceeds blob_settings.max_single_put_size
(default 64 * 1024 * 1024). Starting from a SAS URL.
object = io.BytesIO(bytearray(1024*1024*100))
blob = BlobClient.from_blob_url(url)
blob.upload_blob(
object,
headers={'x-custom-header':'value'}, # BUG in the Azure SDK
)
Expected behavior
The headers
parameter to upload_blob
should work for both single PUT uploads and multi-block uploads.
Fix appears to be just passing headers
to upload_data_chunks
1 2 and upload_substream_blocks
1 2 in upload_block_blob
. Not sure where else this may show up.
Additional context
We use a custom outgoing reverse proxy that expects certain headers.
Workaround the issue with a raw_request_hook
.
def hook(args):
args.http_request.headers.update({'x-custom-header':'value'})
blob = BlobClient.from_blob_url(url)
blob.upload_blob(
object,
raw_request_hook=hook,
)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Hi @jboelter just wanted to let you know that we have a PR up for this issue. I’ll let you know once its merged.
Hi @jboelter
It looks like we intended to only add the customized header in the exact “write” operation (change blob content) which is upload blob or commit block list operation. So it’s not a bug… While I think it doesn’t hurt if we add it to all internal requests! We will post a pr to add customized header to all sub requests soon!