Skip to content

Commit 29e3680

Browse files
authored
Merge pull request #231844 from pauljewellmsft/pauljewell-copy-update
Updates for copy blob
2 parents f178bbd + ab62cf4 commit 29e3680

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

articles/storage/blobs/storage-blob-copy.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ The source blob for a copy operation may be one of the following types:
3434
- Blob snapshot
3535
- Blob version
3636

37-
If the destination blob already exists, it must be of the same blob type as the source blob. An existing destination blob will be overwritten.
38-
39-
The destination blob can't be modified while a copy operation is in progress. A destination blob can only have one outstanding copy operation. One way to enforce this requirement is to use a blob lease, as shown in the code example.
37+
If the destination blob already exists, it must be of the same blob type as the source blob, and the existing destination blob will be overwritten. The destination blob can't be modified while a copy operation is in progress, and a destination blob can only have one outstanding copy operation.
4038

4139
The entire source blob or file is always copied. Copying a range of bytes or set of blocks isn't supported. When a blob is copied, its system properties are copied to the destination blob with the same values.
4240

@@ -49,9 +47,24 @@ To copy a blob, call one of the following methods:
4947

5048
The `StartCopyFromUri` and `StartCopyFromUriAsync` methods return a [CopyFromUriOperation](/dotnet/api/azure.storage.blobs.models.copyfromurioperation) object containing information about the copy operation.
5149

52-
The following code example gets a [BlobClient](/dotnet/api/azure.storage.blobs.blobclient) representing an existing blob and copies it to a new blob in a different container within the same storage account. This example also acquires a lease on the source blob before copying so that no other client can modify the blob until the copy is complete and the lease is released.
53-
54-
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/CopyBlob.cs" id="Snippet_CopyBlob":::
50+
The following code example gets a [BlobClient](/dotnet/api/azure.storage.blobs.blobclient) representing an existing blob and copies it to a new blob in a different container within the same storage account.
51+
52+
```csharp
53+
public static async Task CopyBlobAsync(BlobServiceClient blobServiceClient)
54+
{
55+
// Instantiate BlobClient for the source blob and destination blob
56+
BlobClient sourceBlob = blobServiceClient
57+
.GetBlobContainerClient("source-container")
58+
.GetBlobClient("sample-blob.txt");
59+
BlobClient destinationBlob = blobServiceClient
60+
.GetBlobContainerClient("destination-container")
61+
.GetBlobClient("sample-blob.txt");
62+
63+
// Start the copy operation and wait for it to complete
64+
CopyFromUriOperation copyOperation = await destinationBlob.StartCopyFromUriAsync(sourceBlob.Uri);
65+
await copyOperation.WaitForCompletionAsync();
66+
}
67+
```
5568

5669
To check the status of a copy operation, you can call [UpdateStatusAsync](/dotnet/api/azure.storage.blobs.models.copyfromurioperation.updatestatusasync#azure-storage-blobs-models-copyfromurioperation-updatestatusasync(system-threading-cancellationtoken)) and parse the response to get the value for the `x-ms-copy-status` header.
5770

0 commit comments

Comments
 (0)