Why is it when downloaded I am not able to open a file which was uploaded to my Azure storage account as a block blob?
Initially I thought it was because of the way I uploaded it. But manually uploaded files when downloaded wont open as well. This is the message I see when I try to open the downloaded file-
Type of file - .jpg Here are the properties of the file on Azure -
My graphql api calls the function below which is written in python -
@mutation.field("fileUpload")
def resolve_fileUpload(_, info, file):
print(file[ containerName ])
file_path = file[ file ] if file in file else None
file_name = file[ fileName ] if fileName in file else None
file_type = file[ fileType ] if fileType in file else None
file_extension = file[ fileExtension ] if fileExtension in file else None
uploaded_date = file[ uploadedDate ] if uploadedDate in file else None
container_name = file[ containerName ] if containerName in file else None
try:
container_client = blob_service_client.get_container_client(
container_name)
if not container_client.exists():
container_client.create_container()
container_client.set_container_metadata(
metadata={ Created_Date : uploaded_date})
with open(file_path, "rb") as file:
content_settings = ContentSettings(content_type= image/jpeg )
metadata = { File_Name : file_name, Uploaded_Date : uploaded_date, Container_Name : container_name,
File_Type : file_type, File_Extension : file_extension}
result = container_client.upload_blob(
name=file_name, data=file_path, metadata=metadata, content_settings=content_settings)
# result = container_client.upload_blob(
# name=file_name, data=file_path)
except AzureException as e:
if e.status_code == 200:
return {
"status": e.status_code,
"error": "",
"fileUrl": result.url
}
else:
return {
"status": e.status_code,
"error": e.message,
"fileUrl": result.url
}
else:
return {
"status": 200,
"error": "",
"fileUrl": result.url
}