Skip to content

Commit 6ab4c46

Browse files
Edits
1 parent 5c6a442 commit 6ab4c46

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

articles/storage/common/storage-use-data-movement-library.md

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ dotnet add package Azure.Identity
4949
Add these `using` directives to the top of your code file:
5050

5151
```csharp
52+
using Azure;
53+
using Azure.Core;
5254
using Azure.Identity;
5355
using Azure.Storage.DataMovement;
5456
using Azure.Storage.DataMovement.Blobs;
@@ -97,14 +99,14 @@ The following code shows how to create a `StorageResource` object for blob conta
9799
// Create a token credential
98100
TokenCredential tokenCredential = new DefaultAzureCredential();
99101

100-
BlobsStorageResourceProvider provider = new(tokenCredential);
102+
BlobsStorageResourceProvider blobsProvider = new(tokenCredential);
101103

102104
// Get a container resource
103-
StorageResource container = provider.FromContainer(
105+
StorageResource container = await blobsProvider.FromContainerAsync(
104106
new Uri("http://<storage-account-name>.blob.core.windows.net/sample-container"));
105107

106108
// Get a block blob resource - default is block blob
107-
StorageResource blockBlob = provider.FromBlob(
109+
StorageResource blockBlob = await blobsProvider.FromBlobAsync(
108110
new Uri("http://<storage-account-name>.blob.core.windows.net/sample-container/sample-block-blob"),
109111
new BlockBlobStorageResourceOptions());
110112

@@ -117,17 +119,15 @@ You can also create a `StorageResource` object using a client object from **Azur
117119
// Create a token credential
118120
TokenCredential tokenCredential = new DefaultAzureCredential();
119121

120-
BlobsStorageResourceProvider provider = new(tokenCredential);
121-
122122
BlobContainerClient blobContainerClient = new(
123123
new Uri("https://<storage-account-name>.blob.core.windows.net/sample-container"),
124124
tokenCredential);
125-
StorageResource containerResource = provider.FromClient(blobContainerClient);
125+
StorageResource containerResource = BlobsStorageResourceProvider.FromClient(blobContainerClient);
126126

127127
BlockBlobClient blockBlobClient = new(
128128
new Uri("https://<storage-account-name>.blob.core.windows.net/sample-container/sample-block-blob"),
129129
tokenCredential);
130-
StorageResource blockBlobResource = provider.FromClient(blockBlobClient);
130+
StorageResource blockBlobResource = BlobsStorageResourceProvider.FromClient(blockBlobClient);
131131

132132
// Use a similar approach to get a page blob or append blob resource
133133
```
@@ -154,16 +154,14 @@ TokenCredential tokenCredential = new DefaultAzureCredential();
154154

155155
TransferManager transferManager = new(new TransferManagerOptions());
156156

157-
LocalFilesStorageResourceProvider localFilesProvider = new();
158-
159157
BlobsStorageResourceProvider blobsProvider = new(tokenCredential);
160158

161159
string localFilePath = "C:/path/to/file.txt";
162160
Uri blobUri = new Uri("https://<storage-account-name>.blob.core.windows.net/sample-container/sample-blob");
163161

164162
TransferOperation transferOperation = await transferManager.StartTransferAsync(
165-
sourceResource: localFilesProvider.FromFile(localFilePath),
166-
destinationResource: blobsProvider.FromBlob(
163+
sourceResource: LocalFilesStorageResourceProvider.FromFile(localFilePath),
164+
destinationResource: await blobsProvider.FromBlobAsync(
167165
new Uri(blobUri)));
168166
await transferOperation.WaitForCompletionAsync();
169167
```
@@ -179,20 +177,20 @@ Uri sourceContainerUri = new Uri("https://<storage-account-name>.blob.core.windo
179177
Uri destinationContainerUri = new Uri("https://<storage-account-name>.blob.core.windows.net/dest-container");
180178

181179
TransferOperation transferOperation = await transferManager.StartTransferAsync(
182-
sourceResource: blobsProvider.FromContainer(
180+
sourceResource: await blobsProvider.FromContainerAsync(
183181
sourceContainerUri,
184182
new BlobStorageResourceContainerOptions()
185183
{
186-
BlobDirectoryPrefix = "source/directory/prefix"
184+
BlobPrefix = "source/directory/prefix"
187185
}),
188186
destinationResource: blobsProvider.FromContainer(
189187
destinationContainerUri,
190188
new BlobStorageResourceContainerOptions()
191189
{
192190
// All source blobs are copied as a single type of destination blob
193191
// 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"
196194
}
197195
)
198196
);
@@ -208,8 +206,8 @@ Uri destinationBlobUri = new Uri(
208206
"https://<storage-account-name>.blob.core.windows.net/dest-container/dest-blob");
209207

210208
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()));
213211
await transferOperation.WaitForCompletionAsync();
214212
```
215213

@@ -227,15 +225,12 @@ The following code example shows how to initialize a `TransferManager` object th
227225
// Create a token credential
228226
TokenCredential tokenCredential = new DefaultAzureCredential();
229227

230-
LocalFilesStorageResourceProvider localFilesProvider = new();
231-
232228
BlobsStorageResourceProvider blobsProvider = new(tokenCredential);
233229

234230
TransferManager transferManager = new(new TransferManagerOptions()
235231
{
236-
ResumeProviders = new List<StorageResourceProvider>()
232+
ProvidersForResuming = new List<StorageResourceProvider>()
237233
{
238-
localFilesProvider,
239234
blobsProvider
240235
}
241236
});
@@ -272,7 +267,7 @@ async Task CheckTransfersAsync(TransferManager transferManager)
272267
await foreach (TransferOperation transfer in transferManager.GetTransfersAsync())
273268
{
274269
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));
276271
}
277272
}
278273
```
@@ -303,7 +298,7 @@ async Task<TransferOperation> ListenToTransfersAsync(
303298
{
304299
using (StreamWriter logStream = File.AppendText("path/to/log/file"))
305300
{
306-
logStream.WriteLine($"File Completed Transfer: {args.SourceResource.Uri.AbsoluteUri}");
301+
logStream.WriteLine($"File Completed Transfer: {args.Source.Uri.AbsoluteUri}");
307302
}
308303
return Task.CompletedTask;
309304
};
@@ -318,6 +313,20 @@ async Task<TransferOperation> ListenToTransfersAsync(
318313

319314
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.
320315

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+
321330
The following code example shows how to instantiate a `BlobContainerClient` for a blob container named `sample-container`:
322331

323332
```csharp
@@ -334,15 +343,17 @@ BlobContainerClient containerClient = client.GetBlobContainerClient("sample-cont
334343
The following code example shows how to upload local directory contents to `sample-container` using `UploadDirectoryAsync`:
335344

336345
```csharp
337-
TransferOperation transfer = await containerClient.UploadDirectoryAsync("local/directory/path");
346+
TransferOperation transfer = await containerClient
347+
.UploadDirectoryAsync(WaitUntil.Started, "local/directory/path");
338348

339349
await transfer.WaitForCompletionAsync();
340350
```
341351

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`:
343353

344354
```csharp
345-
TransferOperation transfer = await containerClient.DownloadToDirectoryAsync("local/directory/path");
355+
TransferOperation transfer = await containerClient
356+
.DownloadToDirectoryAsync(WaitUntil.Started, "local/directory/path");
346357

347358
await transfer.WaitForCompletionAsync();
348359
```

0 commit comments

Comments
 (0)