@@ -49,6 +49,8 @@ dotnet add package Azure.Identity
49
49
Add these ` using ` directives to the top of your code file:
50
50
51
51
``` csharp
52
+ using Azure ;
53
+ using Azure .Core ;
52
54
using Azure .Identity ;
53
55
using Azure .Storage .DataMovement ;
54
56
using Azure .Storage .DataMovement .Blobs ;
@@ -97,14 +99,14 @@ The following code shows how to create a `StorageResource` object for blob conta
97
99
// Create a token credential
98
100
TokenCredential tokenCredential = new DefaultAzureCredential ();
99
101
100
- BlobsStorageResourceProvider provider = new (tokenCredential );
102
+ BlobsStorageResourceProvider blobsProvider = new (tokenCredential );
101
103
102
104
// Get a container resource
103
- StorageResource container = provider . FromContainer (
105
+ StorageResource container = await blobsProvider . FromContainerAsync (
104
106
new Uri (" http://<storage-account-name>.blob.core.windows.net/sample-container" ));
105
107
106
108
// Get a block blob resource - default is block blob
107
- StorageResource blockBlob = provider . FromBlob (
109
+ StorageResource blockBlob = await blobsProvider . FromBlobAsync (
108
110
new Uri (" http://<storage-account-name>.blob.core.windows.net/sample-container/sample-block-blob" ),
109
111
new BlockBlobStorageResourceOptions ());
110
112
@@ -117,17 +119,15 @@ You can also create a `StorageResource` object using a client object from **Azur
117
119
// Create a token credential
118
120
TokenCredential tokenCredential = new DefaultAzureCredential ();
119
121
120
- BlobsStorageResourceProvider provider = new (tokenCredential );
121
-
122
122
BlobContainerClient blobContainerClient = new (
123
123
new Uri (" https://<storage-account-name>.blob.core.windows.net/sample-container" ),
124
124
tokenCredential );
125
- StorageResource containerResource = provider .FromClient (blobContainerClient );
125
+ StorageResource containerResource = BlobsStorageResourceProvider .FromClient (blobContainerClient );
126
126
127
127
BlockBlobClient blockBlobClient = new (
128
128
new Uri (" https://<storage-account-name>.blob.core.windows.net/sample-container/sample-block-blob" ),
129
129
tokenCredential );
130
- StorageResource blockBlobResource = provider .FromClient (blockBlobClient );
130
+ StorageResource blockBlobResource = BlobsStorageResourceProvider .FromClient (blockBlobClient );
131
131
132
132
// Use a similar approach to get a page blob or append blob resource
133
133
```
@@ -154,16 +154,14 @@ TokenCredential tokenCredential = new DefaultAzureCredential();
154
154
155
155
TransferManager transferManager = new (new TransferManagerOptions ());
156
156
157
- LocalFilesStorageResourceProvider localFilesProvider = new ();
158
-
159
157
BlobsStorageResourceProvider blobsProvider = new (tokenCredential );
160
158
161
159
string localFilePath = " C:/path/to/file.txt" ;
162
160
Uri blobUri = new Uri (" https://<storage-account-name>.blob.core.windows.net/sample-container/sample-blob" );
163
161
164
162
TransferOperation transferOperation = await transferManager .StartTransferAsync (
165
- sourceResource : localFilesProvider .FromFile (localFilePath ),
166
- destinationResource : blobsProvider .FromBlob (
163
+ sourceResource : LocalFilesStorageResourceProvider .FromFile (localFilePath ),
164
+ destinationResource : await blobsProvider .FromBlobAsync (
167
165
new Uri (blobUri )));
168
166
await transferOperation .WaitForCompletionAsync ();
169
167
```
@@ -179,20 +177,20 @@ Uri sourceContainerUri = new Uri("https://<storage-account-name>.blob.core.windo
179
177
Uri destinationContainerUri = new Uri (" https://<storage-account-name>.blob.core.windows.net/dest-container" );
180
178
181
179
TransferOperation transferOperation = await transferManager .StartTransferAsync (
182
- sourceResource : blobsProvider .FromContainer (
180
+ sourceResource : await blobsProvider .FromContainerAsync (
183
181
sourceContainerUri ,
184
182
new BlobStorageResourceContainerOptions ()
185
183
{
186
- BlobDirectoryPrefix = " source/directory/prefix"
184
+ BlobPrefix = " source/directory/prefix"
187
185
}),
188
186
destinationResource : blobsProvider .FromContainer (
189
187
destinationContainerUri ,
190
188
new BlobStorageResourceContainerOptions ()
191
189
{
192
190
// All source blobs are copied as a single type of destination blob
193
191
// Defaults to block blob, if not specified
194
- BlobType = new ( BlobType .Block ) ,
195
- BlobDirectoryPrefix = " destination/directory/prefix"
192
+ BlobType = BlobType .Block ,
193
+ BlobPrefix = " destination/directory/prefix"
196
194
}
197
195
)
198
196
);
@@ -208,8 +206,8 @@ Uri destinationBlobUri = new Uri(
208
206
" https://<storage-account-name>.blob.core.windows.net/dest-container/dest-blob" );
209
207
210
208
TransferOperation transferOperation = await transferManager .StartTransferAsync (
211
- sourceResource : blobs . FromBlob (sourceBlobUri ),
212
- destinationResource : blobs . FromBlob (destinationBlobUri , new BlockBlobStorageResourceOptions ()));
209
+ sourceResource : await blobsProvider . FromBlobAsync (sourceBlobUri ),
210
+ destinationResource : await blobsProvider . FromBlobAsync (destinationBlobUri , new BlockBlobStorageResourceOptions ()));
213
211
await transferOperation .WaitForCompletionAsync ();
214
212
```
215
213
@@ -227,15 +225,12 @@ The following code example shows how to initialize a `TransferManager` object th
227
225
// Create a token credential
228
226
TokenCredential tokenCredential = new DefaultAzureCredential ();
229
227
230
- LocalFilesStorageResourceProvider localFilesProvider = new ();
231
-
232
228
BlobsStorageResourceProvider blobsProvider = new (tokenCredential );
233
229
234
230
TransferManager transferManager = new (new TransferManagerOptions ()
235
231
{
236
- ResumeProviders = new List <StorageResourceProvider >()
232
+ ProvidersForResuming = new List <StorageResourceProvider >()
237
233
{
238
- localFilesProvider ,
239
234
blobsProvider
240
235
}
241
236
});
@@ -272,7 +267,7 @@ async Task CheckTransfersAsync(TransferManager transferManager)
272
267
await foreach (TransferOperation transfer in transferManager .GetTransfersAsync ())
273
268
{
274
269
using StreamWriter logStream = File .AppendText (" path/to/log/file" );
275
- logStream .WriteLine (Enum .GetName (typeof (TransferStatus ), transfer .TransferStatus ));
270
+ logStream .WriteLine (Enum .GetName (typeof (TransferStatus ), transfer .Status ));
276
271
}
277
272
}
278
273
```
@@ -303,7 +298,7 @@ async Task<TransferOperation> ListenToTransfersAsync(
303
298
{
304
299
using (StreamWriter logStream = File .AppendText (" path/to/log/file" ))
305
300
{
306
- logStream .WriteLine ($" File Completed Transfer: {args .SourceResource .Uri .AbsoluteUri }" );
301
+ logStream .WriteLine ($" File Completed Transfer: {args .Source .Uri .AbsoluteUri }" );
307
302
}
308
303
return Task .CompletedTask ;
309
304
};
@@ -318,6 +313,20 @@ async Task<TransferOperation> ListenToTransfersAsync(
318
313
319
314
For applications with existing code that uses the ` BlobContainerClient ` class from ** Azure.Storage.Blobs** , you can use extension methods to start transfers directly from a ` BlobContainerClient ` object. The extension methods are provided in the [ BlobContainerClientExtensions] ( /dotnet/api/azure.storage.blobs.blobcontainerclientextensions ) class (or [ ShareDirectoryClientExtensions] ( /dotnet/api/azure.storage.files.shares.sharedirectoryclientextensions ) for Azure Files), and provide some of the benefits of using ` TransferManager ` with minimal code changes. In this section, you learn how to use the extension methods to perform transfers from a ` BlobContainerClient ` object.
320
315
316
+ Install the ** Azure.Storage.Blobs** package if you don't have it already:
317
+
318
+ ``` dotnetcli
319
+ dotnet add package Azure.Storage.Blobs
320
+ ```
321
+
322
+ Add the following ` using ` directives to the top of your code file:
323
+
324
+ ``` csharp
325
+ using Azure .Storage .Blobs ;
326
+ using Azure .Storage .Blobs .Models ;
327
+ ```
328
+
329
+
321
330
The following code example shows how to instantiate a ` BlobContainerClient ` for a blob container named ` sample-container ` :
322
331
323
332
``` csharp
@@ -334,15 +343,17 @@ BlobContainerClient containerClient = client.GetBlobContainerClient("sample-cont
334
343
The following code example shows how to upload local directory contents to ` sample-container ` using ` UploadDirectoryAsync ` :
335
344
336
345
``` csharp
337
- TransferOperation transfer = await containerClient .UploadDirectoryAsync (" local/directory/path" );
346
+ TransferOperation transfer = await containerClient
347
+ .UploadDirectoryAsync (WaitUntil .Started , " local/directory/path" );
338
348
339
349
await transfer .WaitForCompletionAsync ();
340
350
```
341
351
342
- The following code example shows how to download the contents of ` sample-container ` to a local directory using ` DownloadDirectoryAsync ` :
352
+ The following code example shows how to download the contents of ` sample-container ` to a local directory using ` DownloadToDirectoryAsync ` :
343
353
344
354
``` csharp
345
- TransferOperation transfer = await containerClient .DownloadToDirectoryAsync (" local/directory/path" );
355
+ TransferOperation transfer = await containerClient
356
+ .DownloadToDirectoryAsync (WaitUntil .Started , " local/directory/path" );
346
357
347
358
await transfer .WaitForCompletionAsync ();
348
359
```
0 commit comments