本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.GetSharedAccessSignature方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlockBlob.GetSharedAccessSignature方法的具体用法?C# CloudBlockBlob.GetSharedAccessSignature怎么用?C# CloudBlockBlob.GetSharedAccessSignature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob
的用法示例。
在下文中一共展示了CloudBlockBlob.GetSharedAccessSignature方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetContainerBlobUri
/// <summary>
/// Get blob's SaS Uri
/// </summary>
/// <param name="blob"></param>
/// <param name="permissionType"></param>
/// <returns></returns>
public string GetContainerBlobUri(CloudBlockBlob blob, string permissionType)
{
SharedAccessBlobPolicy sasConstraints = CreateSASPermission(permissionType);
//Generate the shared access signature on the blob, setting the constraints directly on the signature.
string sasBlobToken = blob.GetSharedAccessSignature(sasConstraints);
//Return the URI string for the container, including the SAS token.
return blob.Uri + sasBlobToken;
}
示例2: GetSasForBlob
/// <summary>
/// Generate a blob SAS
/// </summary>
/// <param name="blob">CloudBlockBlob</param>
/// <returns>SAS string for the specified CLoudBlockBlob</returns>
private static string GetSasForBlob(CloudBlockBlob blob)
{
if (blob == null)
{
throw new ArgumentNullException("blob can't be null");
}
var sas = blob.GetSharedAccessSignature(
new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List,
SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(30),
});
return string.Format(CultureInfo.InvariantCulture, "{0}{1}", blob.Uri, sas);
}
示例3: getSasForBlob
private String getSasForBlob(StorageCredentials credentials, String blobUri, String verb)
{
CloudBlockBlob blob = new CloudBlockBlob(new Uri(blobUri), credentials);
var permission = SharedAccessBlobPermissions.Write;
if (verb == "DELETE")
{
permission = SharedAccessBlobPermissions.Delete;
}
var sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
Permissions = permission,
SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(15),
});
return string.Format(CultureInfo.InvariantCulture, "{0}{1}", blob.Uri, sas);
}
示例4: GetSasForBlob
public string GetSasForBlob(CloudBlockBlob blob, SharedAccessBlobPermissions permission)
{
var sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
Permissions = permission,
SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(2),
});
return string.Format(CultureInfo.InvariantCulture, "{0}{1}", blob.Uri, sas);
}
示例5: GetSaSForBlob
public string GetSaSForBlob(CloudBlockBlob blob, string policyId)
{
var sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy(), policyId);
return string.Format(CultureInfo.InvariantCulture, "{0}{1}", blob.Uri, sas);
}
示例6: UploadImage
private string UploadImage(string encodedImage)
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
"");
//Sensitive information was replaced with ** from the above string for protection
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("images");
//Create the "images" container if it doesn't already exist.
container.CreateIfNotExists();
// Retrieve reference to a blob with this name
//Images will be saved in the format "image_[Guid][Date]"
blockBlob = container.GetBlockBlobReference("image_" + Guid.NewGuid() + System.DateTime.Now);
byte[] imageBytes = Convert.FromBase64String(encodedImage);
// create or overwrite the blob named "image_" and the current date and time
blockBlob.UploadFromByteArray(imageBytes, 0, imageBytes.Length);
//Set the expiry time and permissions for the blob.
//Start time is not specified meaning that this SAS is activated immediately
SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
//Access is Valid for a week
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddDays(7);
sasConstraints.Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write;
//Generate the shared access signature on the blob, setting the constraints directly on the signature.
string sasBlobToken = blockBlob.GetSharedAccessSignature(sasConstraints);
//Return the URI string for the container, including the SAS token.
return blockBlob.Uri + sasBlobToken;
}