@@ -103,8 +103,8 @@ async def upload_document_image(
103
103
raise NotImplementedError ("Subclasses must implement this method" )
104
104
105
105
async def download_blob (
106
- self , blob_path : str , user_oid : Optional [str ] = None
107
- ) -> Optional [Union [BlobStorageStreamDownloader , AdlsBlobStorageStreamDownloader ]]:
106
+ self , blob_path : str , user_oid : Optional [str ] = None , as_bytes : bool = False
107
+ ) -> Optional [Union [BlobStorageStreamDownloader , AdlsBlobStorageStreamDownloader , bytes ]]:
108
108
"""
109
109
Downloads a blob from Azure Storage.
110
110
If user_oid is provided, it checks if the blob belongs to the user.
@@ -253,7 +253,7 @@ async def upload_document_image(
253
253
return unquote (file_client .url )
254
254
255
255
async def download_blob (
256
- self , blob_path : str , user_oid : Optional [str ] = None
256
+ self , blob_path : str , user_oid : Optional [str ] = None , as_bytes : bool = False
257
257
) -> Optional [Union [AdlsBlobStorageStreamDownloader , BlobStorageStreamDownloader ]]:
258
258
"""
259
259
Downloads a blob from Azure Data Lake Storage.
@@ -290,7 +290,10 @@ async def download_blob(
290
290
user_directory_client = await self ._ensure_directory (directory_path = directory_path , user_oid = user_oid )
291
291
file_client = user_directory_client .get_file_client (filename )
292
292
blob = await file_client .download_file ()
293
- return blob
293
+ if as_bytes :
294
+ return await blob .readall ()
295
+ else :
296
+ return blob
294
297
except ResourceNotFoundError :
295
298
logger .warning (f"Directory or file not found: { directory_path } /{ filename } " )
296
299
return None
@@ -444,8 +447,8 @@ async def upload_document_image(
444
447
return blob_client .url
445
448
446
449
async def download_blob (
447
- self , blob_path : str , user_oid : Optional [str ] = None
448
- ) -> Optional [Union [BlobStorageStreamDownloader , AdlsBlobStorageStreamDownloader ]]:
450
+ self , blob_path : str , user_oid : Optional [str ] = None , as_bytes : bool = False
451
+ ) -> Optional [Union [BlobStorageStreamDownloader , AdlsBlobStorageStreamDownloader , bytes ]]:
449
452
if user_oid is not None :
450
453
raise ValueError (
451
454
"user_oid is not supported for BlobManager. Use AdlsBlobManager for user-specific operations."
@@ -462,7 +465,10 @@ async def download_blob(
462
465
if not blob .properties :
463
466
logger .warning (f"No blob exists for { blob_path } " )
464
467
return None
465
- return blob
468
+ if as_bytes :
469
+ return await blob .readall ()
470
+ else :
471
+ return blob
466
472
except ResourceNotFoundError :
467
473
logger .warning ("Blob not found: %s" , blob_path )
468
474
return None
0 commit comments