-
Notifications
You must be signed in to change notification settings - Fork 46
/
PutBlobFromURL.cs
65 lines (57 loc) · 2.66 KB
/
PutBlobFromURL.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Azure;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
using Azure.Storage.Sas;
namespace BlobDevGuideBlobs
{
class PutBlobFromURL
{
// <Snippet_CopyWithinAccount_PutBlobFromURL>
//-------------------------------------------------
// Copy a blob from the same storage account
//-------------------------------------------------
public static async Task CopyWithinStorageAccountAsync(
BlobClient sourceBlob,
BlockBlobClient destinationBlob)
{
// Get the source blob URI and create the destination blob
// overwrite param defaults to false
await destinationBlob.SyncUploadFromUriAsync(sourceBlob.Uri/*, overwrite: false*/);
}
// </Snippet_CopyWithinAccount_PutBlobFromURL>
// <Snippet_CopyAcrossAccounts_PutBlobFromURL>
//-------------------------------------------------
// Copy a blob from a different storage account
//-------------------------------------------------
public static async Task CopyAcrossStorageAccountsAsync(
BlobClient sourceBlob,
BlockBlobClient destinationBlob)
{
// Note: to use GenerateSasUri() for the source blob, the
// source blob client must be authorized via account key
// Set the SAS token to expire in 60 minutes, as an example
DateTimeOffset expiresOn = DateTimeOffset.UtcNow.AddMinutes(60);
// Create a Uri object with a SAS token appended - specify Read (r) permissions
Uri sourceBlobSASURI = sourceBlob.GenerateSasUri(BlobSasPermissions.Read, expiresOn);
// Get the source blob URI and create the destination blob
// overwrite param defaults to false
await destinationBlob.SyncUploadFromUriAsync(sourceBlobSASURI/*, overwrite: false*/);
}
// </Snippet_CopyAcrossAccounts_PutBlobFromURL>
// <Snippet_CopyFromExternalSource_PutBlobFromURL>
//-------------------------------------------------
// Copy a blob from an external source
//-------------------------------------------------
public static async Task CopyFromExternalSourceAsync(
string sourceLocation,
BlockBlobClient destinationBlob)
{
Uri sourceUri = new(sourceLocation);
// Create the destination blob from the source URL
// overwrite param defaults to false
await destinationBlob.SyncUploadFromUriAsync(sourceUri/*, overwrite: false*/);
}
// </Snippet_CopyFromExternalSource_PutBlobFromURL>
}
}