本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.GetSharedAccessSignature方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobContainer.GetSharedAccessSignature方法的具体用法?C# CloudBlobContainer.GetSharedAccessSignature怎么用?C# CloudBlobContainer.GetSharedAccessSignature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
的用法示例。
在下文中一共展示了CloudBlobContainer.GetSharedAccessSignature方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetContainerSasUri
static string GetContainerSasUri(CloudBlobContainer container)
{
SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24);
sasConstraints.Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.List;
string sasContainerToken = container.GetSharedAccessSignature(sasConstraints);
return container.Uri + sasContainerToken;
}
示例2: GetReadAccessSignature
public static string GetReadAccessSignature(CloudBlobContainer container)
{
var signature = container.GetSharedAccessSignature(new SharedAccessBlobPolicy {
Permissions = SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Read,
SharedAccessExpiryTime = DateTimeOffset.Now.AddDays(7),
});
return container.Uri + signature;
}
示例3: GetContainerSasUri
//private CloudBlobClient blobclient;
/// <summary>
/// Get Container's SaS Uri
/// </summary>
/// <param name="blobclient"></param>
/// <param name="container"></param>
/// <param name="permissionType">READ,WRITE,LIST OR DELETE e.g. RWLD</param>
/// <returns>Uri for container</returns>
public string GetContainerSasUri(CloudBlobContainer container, string permissionType)
{
SharedAccessBlobPolicy sasConstraints = CreateSASPermission(permissionType);
//Generate the shared access signature on the container. In this case, all of the constraints for the
//shared access signature are specified on the stored access policy.
string sasContainerToken = container.GetSharedAccessSignature(sasConstraints);
//Return the URI string for the container, including the SAS token.
return container.Uri + sasContainerToken;
}
示例4: GetContainerSasUri
static string GetContainerSasUri(CloudBlobContainer container)
{
//Set the expiry time and permissions for the container.
//In this case no start time is specified, so the shared access signature becomes valid immediately.
SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24);
sasConstraints.SharedAccessStartTime = DateTime.UtcNow;
sasConstraints.Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.List;
//Generate the shared access signature on the container, setting the constraints directly on the signature.
string sasContainerToken = container.GetSharedAccessSignature(sasConstraints);
//Return the URI string for the container, including the SAS token.
return container.Uri + sasContainerToken;
}
示例5: CreateAssetFromBlob
//TODO: move to workerEncoder
private IAsset CreateAssetFromBlob(CloudBlobContainer externalMediaBlobContainer, string ExternalBlobName, CloudBlobClient assetBlobClient, string MediaServicesBlobName, string myProcessId)
{
// Create a new asset.
//myProcessId = Guid.NewGuid().ToString();
CloudMediaContext MediaContext = ObtainContext(_accountMediaName, _accountMediaKey);
string assetName = string.Format("{0}_{1}_Butler_{2}", externalMediaBlobContainer.Name, ExternalBlobName, myProcessId);
IAsset asset = MediaContext.Assets.Create(assetName, AssetCreationOptions.None);
IAccessPolicy writePolicy=MediaContext.AccessPolicies.Create("writePolicy_" + assetName, TimeSpan.FromMinutes(120), AccessPermissions.Write);
ILocator destinationLocator=MediaContext.Locators.CreateLocator(LocatorType.Sas, asset, writePolicy);
string assetContainerName = (new Uri(destinationLocator.Path)).Segments[1];
CloudBlobContainer assetContainer = assetBlobClient.GetContainerReference(assetContainerName);
CloudBlockBlob ExternalBlob = externalMediaBlobContainer.GetBlockBlobReference(ExternalBlobName);
CloudBlockBlob assetBlob = assetContainer.GetBlockBlobReference(MediaServicesBlobName);
var sas = externalMediaBlobContainer.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15),
SharedAccessExpiryTime = DateTime.UtcNow.AddDays(7),
Permissions = SharedAccessBlobPermissions.Read,
});
var srcBlockBlobSasUri = string.Format("{0}{1}", ExternalBlob.Uri, sas);
assetBlob.StartCopyFromBlob(new Uri(srcBlockBlobSasUri));
CloudBlockBlob blobStatusCheck;
blobStatusCheck = (CloudBlockBlob)assetContainer.GetBlobReferenceFromServer(MediaServicesBlobName);
while (blobStatusCheck.CopyState.Status == CopyStatus.Pending)
{
Task.Delay(TimeSpan.FromSeconds(10d)).Wait();
Trace.TraceInformation("Waiting copy of " + blobStatusCheck.Name);
blobStatusCheck = (CloudBlockBlob)assetContainer.GetBlobReferenceFromServer(MediaServicesBlobName);
}
assetBlob.FetchAttributes();
var assetFile = asset.AssetFiles.Create(MediaServicesBlobName);
destinationLocator.Delete();
writePolicy.Delete();
//// Refresh the asset.
asset = MediaContext.Assets.Where(a => a.Id == asset.Id).FirstOrDefault();
return asset;
}
示例6: startCopyBlob
/// <summary>
/// Copy Blob from Origin to Target Container
/// </summary>
/// <param name="OriginContainer"></param>
/// <param name="OriginBlobURL"></param>
/// <param name="DestContainer"></param>
/// <param name="DestBlobURL"></param>
private void startCopyBlob(CloudBlobContainer OriginContainer, string OriginBlobURL, CloudBlobContainer DestContainer, string DestBlobURL)
{
//Destination
Uri destinUri = new Uri(DestBlobURL);
string destinBlobName = Uri.UnescapeDataString(destinUri.Segments[destinUri.Segments.Count() - 1]);
CloudBlockBlob destinBlockBloc = DestContainer.GetBlockBlobReference(destinBlobName);
DestContainer.SetPermissions(new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
}
);
//Origin
Uri originUri = new Uri(OriginBlobURL);
string originBlobName = Uri.UnescapeDataString(originUri.Segments[originUri.Segments.Count() - 1]);
CloudBlockBlob originBlockBlob = OriginContainer.GetBlockBlobReference(originBlobName);
var sas = OriginContainer.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15),
SharedAccessExpiryTime = DateTime.UtcNow.AddDays(7),
Permissions = SharedAccessBlobPermissions.Read,
});
var srcBlockBlobSasUri = string.Format("{0}{1}", Uri.UnescapeDataString(originBlockBlob.Uri.AbsoluteUri), sas);
//Start Copy
destinBlockBloc.StartCopyFromBlob(new Uri(srcBlockBlobSasUri));
}
示例7: BuildSAS
private static string BuildSAS(CloudBlobContainer container)
{
var sas = container.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTime.UtcNow.AddYears(2),
Permissions =
SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Delete |
SharedAccessBlobPermissions.List
});
return sas;
}
示例8: CopyBlobs
public static void CopyBlobs(
CloudBlobContainer srcContainer,
string policyId,
CloudBlobContainer destContainer)
{
// get the SAS token to use for all blobs
string blobToken = srcContainer.GetSharedAccessSignature(
new SharedAccessBlobPolicy(), policyId);
var srcBlobList = srcContainer.ListBlobs(null, false);
foreach (var src in srcBlobList)
{
var srcBlob = src as CloudBlob;
try {
// Create appropriate destination blob type to match the source blob
CloudBlob destBlob;
if (srcBlob.Properties.BlobType == BlobType.BlockBlob)
{
destBlob = destContainer.GetBlockBlobReference(srcBlob.Name);
}
else
{
destBlob = destContainer.GetPageBlobReference(srcBlob.Name);
}
// copy using src blob as SAS
// destBlob.StartCopyFromBlob(new Uri(srcBlob.Uri.AbsoluteUri + blobToken));
destBlob.StartCopy(new Uri(srcBlob.Uri.AbsoluteUri));
Console.WriteLine("Copied: " + srcBlob.Uri.AbsoluteUri);
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
}
}
}
示例9: GenerateContainerUri
/// <summary>
/// Gets the container sas URI.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="expireOffsetInMinute">The expire offset in minute.</param>
/// <param name="permission">The permission.</param>
/// <returns>System.String.</returns>
protected static string GenerateContainerUri(CloudBlobContainer container, int expireOffsetInMinute = 10, SharedAccessBlobPermissions permission = SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Read)
{
//Set the expiry time and permissions for the container.
//In this case no start time is specified, so the shared access signature becomes valid immediately.
var sasConstraints = new SharedAccessBlobPolicy();
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(expireOffsetInMinute);
sasConstraints.Permissions = permission;
//Generate the shared access signature on the container, setting the constraints directly on the signature.
string sasContainerToken = container.GetSharedAccessSignature(sasConstraints);
//Return the URI string for the container, including the SAS token.
return container.Uri + sasContainerToken;
}
示例10: CalculateSASStringForContainer
//calculates SAS string to have access to a container
public static string CalculateSASStringForContainer(string method, CloudBlobContainer container)
{
SharedAccessBlobPolicy sasConstraints = GetSasPolicy(method);
//Generate the shared access signature on the container, setting the constraints directly on the signature.
return container.GetSharedAccessSignature(sasConstraints);
}
示例11: GetContainerSasUriWithPolicy
static string GetContainerSasUriWithPolicy(CloudBlobContainer container, string policyName)
{
//Generate the shared access signature on the container. In this case, all of the constraints for the
//shared access signature are specified on the stored access policy.
string sasContainerToken = container.GetSharedAccessSignature(null, policyName);
//Return the URI string for the container, including the SAS token.
return container.Uri + sasContainerToken;
}
示例12: GetContainerSasUri
/// <summary>
/// Returns a URI containing a SAS for the blob container.
/// </summary>
/// <param name="container">A reference to the container.</param>
/// <param name="storedPolicyName">A string containing the name of the stored access policy. If null, an ad-hoc SAS is created.</param>
/// <returns>A string containing the URI for the container, with the SAS token appended.</returns>
private static string GetContainerSasUri(CloudBlobContainer container, string storedPolicyName = null)
{
string sasContainerToken;
// If no stored policy is specified, create a new access policy and define its constraints.
if (storedPolicyName == null)
{
// Note that the SharedAccessBlobPolicy class is used both to define the parameters of an ad-hoc SAS, and
// to construct a shared access policy that is saved to the container's shared access policies.
SharedAccessBlobPolicy adHocPolicy = new SharedAccessBlobPolicy()
{
// When the start time for the SAS is omitted, the start time is assumed to be the time when the storage service receives the request.
// Omitting the start time for a SAS that is effective immediately helps to avoid clock skew.
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.List
};
// Generate the shared access signature on the container, setting the constraints directly on the signature.
sasContainerToken = container.GetSharedAccessSignature(adHocPolicy, null);
Console.WriteLine("SAS for blob container (ad hoc): {0}", sasContainerToken);
Console.WriteLine();
}
else
{
// Generate the shared access signature on the container. In this case, all of the constraints for the
// shared access signature are specified on the stored access policy, which is provided by name.
// It is also possible to specify some constraints on an ad-hoc SAS and others on the stored access policy.
sasContainerToken = container.GetSharedAccessSignature(null, storedPolicyName);
Console.WriteLine("SAS for blob container (stored access policy): {0}", sasContainerToken);
Console.WriteLine();
}
// Return the URI string for the container, including the SAS token.
return container.Uri + sasContainerToken;
}