12
12
from azure .storage .blob .aio import (
13
13
StorageStreamDownloader as BlobStorageStreamDownloader ,
14
14
)
15
- from azure .storage .filedatalake import DataLakeDirectoryClient
16
- from azure .storage .filedatalake import (
15
+ from azure .storage .filedatalake . aio import DataLakeDirectoryClient , FileSystemClient
16
+ from azure .storage .filedatalake . aio import (
17
17
StorageStreamDownloader as AdlsBlobStorageStreamDownloader ,
18
18
)
19
- from azure .storage .filedatalake .aio import FileSystemClient
20
19
from PIL import Image , ImageDraw , ImageFont
21
20
22
21
from .listfilestrategy import File
@@ -254,16 +253,17 @@ async def upload_document_image(
254
253
255
254
async def download_blob (
256
255
self , blob_path : str , user_oid : Optional [str ] = None , as_bytes : bool = False
257
- ) -> Optional [Union [AdlsBlobStorageStreamDownloader , BlobStorageStreamDownloader ]]:
256
+ ) -> Optional [Union [AdlsBlobStorageStreamDownloader , bytes ]]:
258
257
"""
259
258
Downloads a blob from Azure Data Lake Storage.
260
259
261
260
Args:
262
261
blob_path: The path to the blob in the format {user_oid}/{document_name}/images/{image_name}
263
262
user_oid: The user's object ID
263
+ as_bytes: If True, returns the blob as bytes, otherwise returns a stream downloader
264
264
265
265
Returns:
266
- Optional[Union[AdlsBlobStorageStreamDownloader, BlobStorageStreamDownloader ]]: A stream downloader for the blob, or None if not found
266
+ Optional[Union[AdlsBlobStorageStreamDownloader, bytes ]]: A stream downloader for the blob, or bytes if as_bytes=True , or None if not found
267
267
"""
268
268
if user_oid is None :
269
269
logger .warning ("user_oid must be provided for Data Lake Storage operations." )
@@ -322,8 +322,8 @@ async def remove_blob(self, filename: str, user_oid: str) -> None:
322
322
await file_client .delete_file ()
323
323
324
324
# Try to delete any associated image directories
325
+ image_directory_path = self ._get_image_directory_path (filename , user_oid )
325
326
try :
326
- image_directory_path = self ._get_image_directory_path (filename , user_oid )
327
327
image_directory_client = await self ._ensure_directory (
328
328
directory_path = image_directory_path , user_oid = user_oid
329
329
)
@@ -408,7 +408,7 @@ def get_managedidentity_connectionstring(self):
408
408
raise ValueError ("Account, resource group, and subscription ID must be set to generate connection string." )
409
409
return f"ResourceId=/subscriptions/{ self .subscription_id } /resourceGroups/{ self .resource_group } /providers/Microsoft.Storage/storageAccounts/{ self .account } ;"
410
410
411
- async def upload_blob (self , file : File ) -> Optional [ list [ str ]] :
411
+ async def upload_blob (self , file : File ) -> str :
412
412
container_client = self .blob_service_client .get_container_client (self .container )
413
413
if not await container_client .exists ():
414
414
await container_client .create_container ()
@@ -421,6 +421,8 @@ async def upload_blob(self, file: File) -> Optional[list[str]]:
421
421
blob_client = await container_client .upload_blob (blob_name , reopened_file , overwrite = True )
422
422
file .url = blob_client .url
423
423
424
+ return unquote (file .url )
425
+
424
426
async def upload_document_image (
425
427
self ,
426
428
document_filename : str ,
0 commit comments