當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。