Пример #1
0
        public async Task BlobVersionSas_AllPermissions()
        {
            // Arrange
            await using DisposingContainer test = await GetTestContainerAsync();

            string                     blobName       = GetNewBlobName();
            AppendBlobClient           blob           = InstrumentClient(test.Container.GetAppendBlobClient(blobName));
            Response <BlobContentInfo> createResponse = await blob.CreateAsync();

            IDictionary <string, string> metadata         = BuildMetadata();
            Response <BlobInfo>          metadataResponse = await blob.SetMetadataAsync(metadata);

            BlobSasBuilder blobSasBuilder = new BlobSasBuilder()
            {
                ExpiresOn         = Recording.UtcNow.AddDays(1),
                BlobContainerName = test.Container.Name,
                BlobName          = blobName,
                BlobVersionId     = createResponse.Value.VersionId
            };

            blobSasBuilder.SetPermissions(BlobVersionSasPermissions.All);

            BlobUriBuilder blobUriBuilder = new BlobUriBuilder(blob.Uri)
            {
                VersionId = createResponse.Value.VersionId,
                Sas       = blobSasBuilder.ToSasQueryParameters(GetNewSharedKeyCredentials())
            };

            // Act
            AppendBlobClient sasBlobClient = InstrumentClient(new AppendBlobClient(blobUriBuilder.ToUri(), GetOptions()));
            await sasBlobClient.DeleteAsync();
        }
Пример #2
0
        public async Task AppendBlobSample()
        {
            // Instantiate a new BlobServiceClient using a connection string.
            BlobServiceClient blobServiceClient = new BlobServiceClient(TestConfigurations.DefaultTargetTenant.ConnectionString);

            // Instantiate a new BlobContainerClient
            BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient("mycontainer4");

            try
            {
                // Create new Container in the Service
                await blobContainerClient.CreateAsync();

                // Instantiate a new PageBlobClient
                AppendBlobClient appendBlobClient = blobContainerClient.GetAppendBlobClient("appendblob");

                // Create PageBlob in the Service
                await appendBlobClient.CreateAsync();

                // Append content to AppendBlob
                using (FileStream fileStream = File.OpenRead("Samples/SampleSource.txt"))
                {
                    await appendBlobClient.AppendBlockAsync(fileStream);
                }

                // Download PageBlob
                using (FileStream fileStream = File.Create("AppendDestination.txt"))
                {
                    Response <BlobDownloadInfo> downloadResponse = await appendBlobClient.DownloadAsync();

                    await downloadResponse.Value.Content.CopyToAsync(fileStream);
                }

                // Delete PageBlob in the Service
                await appendBlobClient.DeleteAsync();
            }
            finally
            {
                // Delete Container in the Service
                await blobContainerClient.DeleteAsync();
            }
        }
Пример #3
0
        public async Task BlobVersionIdentitySas_AllPermissions()
        {
            // Arrange
            BlobServiceClient oauthService  = GetServiceClient_OauthAccount();
            string            containerName = GetNewContainerName();
            string            blobName      = GetNewBlobName();

            await using DisposingContainer test = await GetTestContainerAsync(containerName : containerName, service : oauthService);

            Response <UserDelegationKey> userDelegationKey = await oauthService.GetUserDelegationKeyAsync(
                startsOn : null,
                expiresOn : Recording.UtcNow.AddHours(1));

            AppendBlobClient           blob           = InstrumentClient(test.Container.GetAppendBlobClient(blobName));
            Response <BlobContentInfo> createResponse = await blob.CreateAsync();

            IDictionary <string, string> metadata         = BuildMetadata();
            Response <BlobInfo>          metadataResponse = await blob.SetMetadataAsync(metadata);

            BlobSasBuilder blobSasBuilder = new BlobSasBuilder()
            {
                ExpiresOn         = Recording.UtcNow.AddDays(1),
                BlobContainerName = test.Container.Name,
                BlobName          = blobName,
                BlobVersionId     = createResponse.Value.VersionId
            };

            blobSasBuilder.SetPermissions(BlobVersionSasPermissions.All);

            BlobUriBuilder blobUriBuilder = new BlobUriBuilder(blob.Uri)
            {
                VersionId = createResponse.Value.VersionId,
                Sas       = blobSasBuilder.ToSasQueryParameters(userDelegationKey.Value, oauthService.AccountName)
            };

            // Act
            AppendBlobClient sasBlobClient = InstrumentClient(new AppendBlobClient(blobUriBuilder.ToUri(), GetOptions()));
            await sasBlobClient.DeleteAsync();
        }