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


C# CloudBlobContainer.GetSharedAccessSignature方法代码示例

本文整理汇总了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;
 }
开发者ID:faiyaz-shaik,项目名称:Prototypes,代码行数:8,代码来源:Program.cs

示例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;
 }
开发者ID:perokvist,项目名称:messageVault,代码行数:8,代码来源:CloudSetup.cs

示例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;
        }
开发者ID:hangmiao,项目名称:DBLike,代码行数:19,代码来源:GenerateSAS.cs

示例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;
        }
开发者ID:wi5nia,项目名称:Samples,代码行数:15,代码来源:Program.cs

示例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;
        }
开发者ID:sabbour,项目名称:WAMSVODButler,代码行数:43,代码来源:ButlerEncoderPublish.cs

示例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));
        }
开发者ID:pitcrew,项目名称:MediaBlutlerTest01,代码行数:34,代码来源:ProcessReplicaStep.cs

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

示例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);
                }
            }
        }
开发者ID:faiyaz-shaik,项目名称:Prototypes,代码行数:40,代码来源:Program.cs

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

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

示例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;
        }
开发者ID:laurikoobas,项目名称:Azure,代码行数:9,代码来源:Program.cs

示例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;
        }
开发者ID:tamram,项目名称:storage-blob-dotnet-getting-started,代码行数:43,代码来源:Advanced.cs


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