1
- using Cosmos . DataTransfer . Interfaces ;
1
+ using Azure . Storage . Blobs ;
2
+ using Cosmos . DataTransfer . Interfaces ;
2
3
using Microsoft . Extensions . Configuration ;
3
4
using Microsoft . Extensions . Logging ;
5
+ using Azure . Storage . Blobs . Specialized ;
6
+ using Azure . Storage . Blobs . Models ;
4
7
5
8
namespace Cosmos . DataTransfer . AzureBlobStorage
6
9
{
@@ -12,10 +15,20 @@ public async Task WriteToTargetAsync(Func<Stream, Task> writeToStream, IConfigur
12
15
settings . Validate ( ) ;
13
16
14
17
logger . LogInformation ( "Saving file '{File}' to Azure Blob Container '{ContainerName}'" , settings . BlobName , settings . ContainerName ) ;
15
- await BlobWriter . InitializeAzureBlobClient ( settings . ConnectionString , settings . ContainerName , settings . BlobName , cancellationToken ) ;
16
- await using var stream = new MemoryStream ( ) ;
17
- await writeToStream ( stream ) ;
18
- await BlobWriter . WriteToAzureBlob ( stream . ToArray ( ) , settings . MaxBlockSizeinKB , cancellationToken ) ;
18
+
19
+ var account = new BlobContainerClient ( settings . ConnectionString , settings . ContainerName ) ;
20
+ await account . CreateIfNotExistsAsync ( cancellationToken : cancellationToken ) ;
21
+ var blob = account . GetBlockBlobClient ( settings . BlobName ) ;
22
+
23
+ await using var blobStream = await blob . OpenWriteAsync ( true , new BlockBlobOpenWriteOptions
24
+ {
25
+ BufferSize = settings . MaxBlockSizeinKB * 1024L ,
26
+ ProgressHandler = new Progress < long > ( l =>
27
+ {
28
+ logger . LogInformation ( "Transferred {UploadedBytes} bytes to Azure Blob" , l ) ;
29
+ } )
30
+ } , cancellationToken ) ;
31
+ await writeToStream ( blobStream ) ;
19
32
}
20
33
21
34
public IEnumerable < IDataExtensionSettings > GetSettings ( )
0 commit comments