当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlockBlob.GetSharedAccessSignature方法代码示例

本文整理汇总了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;
        }
开发者ID:hangmiao,项目名称:DBLike,代码行数:16,代码来源:GenerateSAS.cs

示例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);
        }
开发者ID:danieros,项目名称:AnimalReUnite,代码行数:20,代码来源:HomeController.cs

示例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);
        }
开发者ID:cephalin,项目名称:ContosoMoments,代码行数:21,代码来源:StorageHelper.cs

示例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);
 }
开发者ID:joergjo,项目名称:HOL-GettingStartedWindowsAzureStorage,代码行数:10,代码来源:PhotoDataServiceContext.cs

示例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);
 }
开发者ID:joergjo,项目名称:HOL-GettingStartedWindowsAzureStorage,代码行数:5,代码来源:PhotoDataServiceContext.cs

示例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;
        }
开发者ID:robbiekenny,项目名称:HomeSecurity-Backend-Part2,代码行数:39,代码来源:SendEmailController.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.GetSharedAccessSignature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。