本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetBlobReferenceFromServerAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobClient.GetBlobReferenceFromServerAsync方法的具体用法?C# CloudBlobClient.GetBlobReferenceFromServerAsync怎么用?C# CloudBlobClient.GetBlobReferenceFromServerAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient
的用法示例。
在下文中一共展示了CloudBlobClient.GetBlobReferenceFromServerAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloudBlobContainerGetBlobReferenceFromServerAsync
public async Task CloudBlobContainerGetBlobReferenceFromServerAsync()
{
CloudBlobContainer container = GetRandomContainerReference();
try
{
await container.CreateAsync();
SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
};
CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb");
await blockBlob.PutBlockListAsync(new List<string>());
CloudPageBlob pageBlob = container.GetPageBlobReference("pb");
await pageBlob.CreateAsync(0);
ICloudBlob blob1 = await container.GetBlobReferenceFromServerAsync("bb");
Assert.IsInstanceOfType(blob1, typeof(CloudBlockBlob));
CloudBlockBlob blob1Snapshot = await ((CloudBlockBlob)blob1).CreateSnapshotAsync();
await blob1.SetPropertiesAsync();
Uri blob1SnapshotUri = new Uri(blob1Snapshot.Uri.AbsoluteUri + "?snapshot=" + blob1Snapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
ICloudBlob blob1SnapshotReference = await container.ServiceClient.GetBlobReferenceFromServerAsync(blob1SnapshotUri);
AssertAreEqual(blob1Snapshot.Properties, blob1SnapshotReference.Properties);
ICloudBlob blob2 = await container.GetBlobReferenceFromServerAsync("pb");
Assert.IsInstanceOfType(blob2, typeof(CloudPageBlob));
CloudPageBlob blob2Snapshot = await ((CloudPageBlob)blob2).CreateSnapshotAsync();
await blob2.SetPropertiesAsync();
Uri blob2SnapshotUri = new Uri(blob2Snapshot.Uri.AbsoluteUri + "?snapshot=" + blob2Snapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
ICloudBlob blob2SnapshotReference = await container.ServiceClient.GetBlobReferenceFromServerAsync(blob2SnapshotUri);
AssertAreEqual(blob2Snapshot.Properties, blob2SnapshotReference.Properties);
ICloudBlob blob3 = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlob.Uri);
Assert.IsInstanceOfType(blob3, typeof(CloudBlockBlob));
ICloudBlob blob4 = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlob.Uri);
Assert.IsInstanceOfType(blob4, typeof(CloudPageBlob));
string blockBlobToken = blockBlob.GetSharedAccessSignature(policy);
StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken);
Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri);
string pageBlobToken = pageBlob.GetSharedAccessSignature(policy);
StorageCredentials pageBlobSAS = new StorageCredentials(pageBlobToken);
Uri pageBlobSASUri = pageBlobSAS.TransformUri(pageBlob.Uri);
ICloudBlob blob5 = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlobSASUri);
Assert.IsInstanceOfType(blob5, typeof(CloudBlockBlob));
ICloudBlob blob6 = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlobSASUri);
Assert.IsInstanceOfType(blob6, typeof(CloudPageBlob));
CloudBlobClient client7 = new CloudBlobClient(container.ServiceClient.BaseUri, blockBlobSAS);
ICloudBlob blob7 = await client7.GetBlobReferenceFromServerAsync(blockBlobSASUri);
Assert.IsInstanceOfType(blob7, typeof(CloudBlockBlob));
CloudBlobClient client8 = new CloudBlobClient(container.ServiceClient.BaseUri, pageBlobSAS);
ICloudBlob blob8 = await client8.GetBlobReferenceFromServerAsync(pageBlobSASUri);
Assert.IsInstanceOfType(blob8, typeof(CloudPageBlob));
}
finally
{
container.DeleteIfExistsAsync().AsTask().Wait();
}
}
示例2: CloudBlobContainerGetBlobReferenceFromServerAsync
public async Task CloudBlobContainerGetBlobReferenceFromServerAsync()
{
CloudBlobContainer container = GetRandomContainerReference();
try
{
await container.CreateAsync();
SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
};
CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb");
await blockBlob.PutBlockListAsync(new List<string>());
CloudPageBlob pageBlob = container.GetPageBlobReference("pb");
await pageBlob.CreateAsync(0);
CloudAppendBlob appendBlob = container.GetAppendBlobReference("ab");
await appendBlob.CreateOrReplaceAsync();
CloudBlobClient client;
ICloudBlob blob;
blob = await container.GetBlobReferenceFromServerAsync("bb");
Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob));
Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri));
CloudBlockBlob blockBlobSnapshot = await ((CloudBlockBlob)blob).CreateSnapshotAsync();
await blob.SetPropertiesAsync();
Uri blockBlobSnapshotUri = new Uri(blockBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + blockBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlobSnapshotUri);
AssertAreEqual(blockBlobSnapshot.Properties, blob.Properties);
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlobSnapshot.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = await container.GetBlobReferenceFromServerAsync("pb");
Assert.IsInstanceOfType(blob, typeof(CloudPageBlob));
Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri));
CloudPageBlob pageBlobSnapshot = await ((CloudPageBlob)blob).CreateSnapshotAsync();
await blob.SetPropertiesAsync();
Uri pageBlobSnapshotUri = new Uri(pageBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + pageBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlobSnapshotUri);
AssertAreEqual(pageBlobSnapshot.Properties, blob.Properties);
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlobSnapshot.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = await container.GetBlobReferenceFromServerAsync("ab");
Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob));
Assert.IsTrue(blob.StorageUri.Equals(appendBlob.StorageUri));
CloudAppendBlob appendBlobSnapshot = await ((CloudAppendBlob)blob).CreateSnapshotAsync();
await blob.SetPropertiesAsync();
Uri appendBlobSnapshotUri = new Uri(appendBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + appendBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(appendBlobSnapshotUri);
AssertAreEqual(appendBlobSnapshot.Properties, blob.Properties);
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(appendBlobSnapshot.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlob.Uri);
Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob));
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlob.Uri);
Assert.IsInstanceOfType(blob, typeof(CloudPageBlob));
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlob.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(appendBlob.Uri);
Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob));
Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(appendBlob.Uri));
Assert.IsNull(blob.StorageUri.SecondaryUri);
blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlob.StorageUri, null, null, null);
Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob));
Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri));
blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlob.StorageUri, null, null, null);
Assert.IsInstanceOfType(blob, typeof(CloudPageBlob));
Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri));
blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(appendBlob.StorageUri, null, null, null);
Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob));
Assert.IsTrue(blob.StorageUri.Equals(appendBlob.StorageUri));
string blockBlobToken = blockBlob.GetSharedAccessSignature(policy);
StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken);
Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri);
StorageUri blockBlobSASStorageUri = blockBlobSAS.TransformUri(blockBlob.StorageUri);
string appendBlobToken = appendBlob.GetSharedAccessSignature(policy);
StorageCredentials appendBlobSAS = new StorageCredentials(appendBlobToken);
Uri appendBlobSASUri = appendBlobSAS.TransformUri(appendBlob.Uri);
StorageUri appendBlobSASStorageUri = appendBlobSAS.TransformUri(appendBlob.StorageUri);
string pageBlobToken = pageBlob.GetSharedAccessSignature(policy);
//.........这里部分代码省略.........
示例3: CloudBlobContainerGetBlobReferenceFromServerTask
public void CloudBlobContainerGetBlobReferenceFromServerTask()
{
CloudBlobContainer container = GetRandomContainerReference();
try
{
container.CreateAsync().Wait();
SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
};
CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb");
blockBlob.PutBlockList(new string[] { });
CloudPageBlob pageBlob = container.GetPageBlobReference("pb");
pageBlob.Create(0);
ICloudBlob blob1 = container.GetBlobReferenceFromServerAsync("bb").Result;
Assert.IsInstanceOfType(blob1, typeof(CloudBlockBlob));
ICloudBlob blob2 = container.GetBlobReferenceFromServerAsync("pb").Result;
Assert.IsInstanceOfType(blob2, typeof(CloudPageBlob));
ICloudBlob blob3 = container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlob.Uri).Result;
Assert.IsInstanceOfType(blob3, typeof(CloudBlockBlob));
ICloudBlob blob4 = container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlob.Uri).Result;
Assert.IsInstanceOfType(blob4, typeof(CloudPageBlob));
string blockBlobToken = blockBlob.GetSharedAccessSignature(policy);
StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken);
Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri);
string pageBlobToken = pageBlob.GetSharedAccessSignature(policy);
StorageCredentials pageBlobSAS = new StorageCredentials(pageBlobToken);
Uri pageBlobSASUri = pageBlobSAS.TransformUri(pageBlob.Uri);
ICloudBlob blob5 = container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlobSASUri).Result;
Assert.IsInstanceOfType(blob5, typeof(CloudBlockBlob));
ICloudBlob blob6 = container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlobSASUri).Result;
Assert.IsInstanceOfType(blob6, typeof(CloudPageBlob));
CloudBlobClient client7 = new CloudBlobClient(container.ServiceClient.BaseUri, blockBlobSAS);
ICloudBlob blob7 = client7.GetBlobReferenceFromServerAsync(blockBlobSASUri).Result;
Assert.IsInstanceOfType(blob7, typeof(CloudBlockBlob));
CloudBlobClient client8 = new CloudBlobClient(container.ServiceClient.BaseUri, pageBlobSAS);
ICloudBlob blob8 = client8.GetBlobReferenceFromServerAsync(pageBlobSASUri).Result;
Assert.IsInstanceOfType(blob8, typeof(CloudPageBlob));
}
finally
{
container.DeleteIfExistsAsync().Wait();
}
}