This is how we are creating a pdf on azure blob storage and reading the file from Azure blob storage
upload_blob and download_blob takes 2 seconds to execute which increases execution time of our API
i tried async but it didnt reduced time. func tools caching also didnt helped
for redis caching we would need a new server
import logging
import os
from azure.storage.blob import ContainerClient
from starlette.config import Config
from datetime import timedelta
from datetime import datetime
import pytz
class azure_storage_account:
def __init__(self, azure_storage_connection_string="",container_name =""):
dir_path = os.getcwd()
config = Config(dir_path + os.sep + '.env')
if azure_storage_connection_string == "":
self.azure_storage_connection_string = config('AZURE_STORAGE_CONNECTION_STRING')
else:
self.azure_storage_connection_string = azure_storage_connection_string
if container_name == "":
self.container_name = config('AZURE_API_FILE_CONTAINER')
else:
self.container_name = container_name
self.container_client = ContainerClient.from_connection_string(conn_str=self.azure_storage_connection_string,container_name=self.container_name)
def create_file(self,file_path,data=""):
try:
blob_client = self.container_client.get_blob_client(file_path)
blob_client.upload_blob(data,overwrite=True)
return True
except Exception as e:
logging.error(e)
return False
def read_file(self,file_path):
try:
file_stream = self.container_client.download_blob(file_path)
file_content = file_stream.readall()
return file_content
except Exception as e:
logging.error(e)
return False