I am looking to simply download an excel blob from Azure Storage, make some modifications and then upload it with a new name using Azure Python SDK v12. I've found several questions on here using v2.x with blockblobservice module. But that is not available in v12. An additional constraint is that I do not want anything locally as this is part of a serverless app.
Here is my code and notations:
from azure.storage.blob import BlobClient
import io
import pandas as pd
#Download Blob: works fine
download_client=BlobClient.from_connection_string(
conn_str=az_str,
container_name=container_name,
blob_name=blob_name)
read = io.BytesIO()
download_stream = download_client.download_blob()
df = pd.read_excel(download_stream.readall())
#Make arbitrary changes: works fine
df_new = df.append(df)
print(df_new)
#Upload Blob: blob is empty
new_blob_name=f'UploadTest.xlsx'
upload_client = BlobClient.from_connection_string(
conn_str=az_str,
container_name=container_name,
blob_name=new_blob_name)
write = io.BytesIO()
df_new.to_excel(write, sheet_name='Test Sample')
upload_client.upload_blob(write, blob_type="BlockBlob", overwrite=True)