'Azure Function: Write data to blob container with specified file format using python

I am developing an Azure function using Python. This function will save data to Azure blob container in json format but I don't know how and where to mention file format explicitly in my following piece of code. Hence seeking the help.

storage_connection_string = 'my_storage_connection_string'

container_name = 'my_container_name_kv'

today = datetime.datetime.today()

blob_client =  BlobClient.from_connection_string(storage_connection_string, container_name=container_name, blob_name=str(today.year) +"/" + str(today.month) + "/" + str(today.day) + "/" + str(msg_id) + ".json")

response_json = '{ "SOURCE": "APETDEV", "TIMESTAMP": "2022-04-25 20:34:45", "TAGERRORS": [] }'

blob_client.upload_blob(response_json, blob_type="AppendBlob")


Solution 1:[1]

Wanted to post a comment to ask for some clarifications but alas couldn't do that yet. I'm not entirely sure what you mean but reading the ms azure sdk docs about blobs and the upload_blob function it says that you can set the "content_settings": 'ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.' Perhaps you are looking for this?

From the doc page:

upload_blob(data: Union[Iterable, IO], blob_type: Union[str, azure.storage.blob._models.BlobType] = <BlobType.BlockBlob: 'BlockBlob'>, length: Optional[int] = None, metadata: Optional[Dict[str, str]] = None, **kwargs) -> Any

Hopefully this helps somewhat...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FerdiS