コード例 #1
0
        public string GetBlobSasUri(string containerName, string blobName)
        {
            //Get a reference to a blob within the container.
            CloudBlockBlob blob = GetBlob(containerName, blobName);

            // Get the standard user access policy to apply to this blob request
            SharedAccessBlobPolicy blobAccessPolicy = AccessPolicyManager.GetStandardUserBlobPolicy();

            //Generate the shared access signature on the blob, setting the constraints directly on the signature.
            string sasBlobToken = blob.GetSharedAccessSignature(blobAccessPolicy);

            //Return the URI string for the container, including the SAS token.
            return(blob.Uri + sasBlobToken);
        }
コード例 #2
0
        // NOTE: This method throws an exception of Type "StorageException" when an invalid container name is provided
        // The message describing the error is on a property of the exception named RequestInformation.HttpStatusMessage
        public CloudBlobContainer TryCreateUserContainer(string containerName)
        {
            // Retrieve a reference to a container.
            CloudBlobContainer container = _azureClient.GetContainerReference(NormalizeContainerName(containerName));

            var wasCreated = false;

            try
            {
                wasCreated = container.CreateIfNotExists();
            }
            catch (StorageException ex)
            {
                throw ex;
            }

            if (wasCreated)
            {
                container.SetPermissions(AccessPolicyManager.GetStandardUserBlobContainerPolicy());
            }

            // If it existed, return the existing reference, otherwise requery the container we created
            return(container);
        }