You are developing a Python backend application that uses the azure-storage-blob SDK (v12). The application needs to overwrite the content of a blob named config.json that has an active lease. The lease ID is 5b8f673d-8d2a-4f5a-9b4e-8c6e2b1a3c5d.
Which of the following code snippets should you use to successfully perform this operation?
- blob_client.upload_blob(data, overwrite=True, lease="5b8f673d-8d2a-4f5a-9b4e-8c6e2b1a3c5d")Answer
- Bblob_client.upload_blob(data, overwrite=True, lease_id="5b8f673d-8d2a-4f5a-9b4e-8c6e2b1a3c5d")
- Clease_client = BlobLeaseClient(blob_client, lease_id="5b8f673d-8d2a-4f5a-9b4e-8c6e2b1a3c5d")
lease_client.upload_blob(data, overwrite=True) - Dblob_client.upload_blob(data, overwrite=True, metadata={"lease-id": "5b8f673d-8d2a-4f5a-9b4e-8c6e2b1a3c5d"})
Answer
blob_client.upload_blob(data, overwrite=True, lease="5b8f673d-8d2a-4f5a-9b4e-8c6e2b1a3c5d")
The correct option correctly uses the 'lease' keyword argument of the 'upload_blob' method, passing the active lease ID. This enables the Azure Storage SDK to include the necessary lease validation headers, allowing the write operation to succeed on the leased blob.
Step-by-Step Solution
Key Concept
To perform modifications on an actively leased blob using the Azure Storage SDK for Python, the lease ID must be passed directly to the upload_blob method using the lease keyword argument.