File size: 674 Bytes
2350be5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b4bf28
2350be5
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

import io
import os
from PIL import Image
from azure.storage.blob import ContainerClient


def get_file_from_azure_blob_storage(path):
    AZURE_SAS_URL_TRD = os.environ["AZURE_SAS_URL_TRD"]
    container_client = ContainerClient.from_container_url(AZURE_SAS_URL_TRD)
    blob_client = container_client.get_blob_client(path)
    stream = blob_client.download_blob().readall()
    file_object = io.BytesIO(stream)
    return file_object


def get_image_from_azure_blob_storage(path):
    base_path = "climateqa/documents/"
    path = os.path.join(base_path, path)
    file_object = get_file_from_azure_blob_storage(path)
    image = Image.open(file_object)
    return image