public async Task SetPropertiesAsync_StaticWebsite() { // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobServiceProperties properties = await service.GetPropertiesAsync(); BlobStaticWebsite originalBlobStaticWebsite = properties.StaticWebsite; string errorDocument404Path = "error/404.html"; string defaultIndexDocumentPath = "index.html"; properties.StaticWebsite = new BlobStaticWebsite { Enabled = true, ErrorDocument404Path = errorDocument404Path, DefaultIndexDocumentPath = defaultIndexDocumentPath }; // Act await service.SetPropertiesAsync(properties); // Assert properties = await service.GetPropertiesAsync(); Assert.IsTrue(properties.StaticWebsite.Enabled); Assert.AreEqual(errorDocument404Path, properties.StaticWebsite.ErrorDocument404Path); Assert.AreEqual(defaultIndexDocumentPath, properties.StaticWebsite.DefaultIndexDocumentPath); // Cleanup properties.StaticWebsite = originalBlobStaticWebsite; await service.SetPropertiesAsync(properties); }
public async Task SetPropertiesAsync() { // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobServiceProperties properties = await service.GetPropertiesAsync(); BlobCorsRule[] originalCors = properties.Cors.ToArray(); properties.Cors = new[] { new BlobCorsRule { MaxAgeInSeconds = 1000, AllowedHeaders = "x-ms-meta-data*,x-ms-meta-target*,x-ms-meta-abc", AllowedMethods = "PUT,GET", AllowedOrigins = "*", ExposedHeaders = "x-ms-meta-*" } }; // Act await service.SetPropertiesAsync(properties); // Assert properties = await service.GetPropertiesAsync(); Assert.AreEqual(1, properties.Cors.Count()); Assert.IsTrue(properties.Cors[0].MaxAgeInSeconds == 1000); // Cleanup properties.Cors = originalCors; await service.SetPropertiesAsync(properties); properties = await service.GetPropertiesAsync(); Assert.AreEqual(originalCors.Count(), properties.Cors.Count()); }
public async Task SetPropertiesAsync_Error() { // Arrange BlobServiceClient service = GetServiceClient_SharedKey(); BlobServiceProperties properties = (await service.GetPropertiesAsync()).Value; BlobServiceClient invalidService = InstrumentClient( new BlobServiceClient( GetServiceClient_SharedKey().Uri, GetOptions())); // Act await TestHelper.AssertExpectedExceptionAsync <RequestFailedException>( invalidService.SetPropertiesAsync(properties), e => { }); }
public async Task DisableSoftDelete() { BlobServiceClient service = GetServiceClient_SharedKey(); Response <BlobServiceProperties> properties = await service.GetPropertiesAsync(); properties.Value.DeleteRetentionPolicy = new BlobRetentionPolicy { Enabled = false }; await service.SetPropertiesAsync(properties); do { await Delay(250); properties = await service.GetPropertiesAsync(); } while (properties.Value.DeleteRetentionPolicy.Enabled); }
public async Task EnableSoftDelete() { BlobServiceClient service = BlobsClientBuilder.GetServiceClient_SharedKey(); Response <BlobServiceProperties> properties = await service.GetPropertiesAsync(); properties.Value.DeleteRetentionPolicy = new BlobRetentionPolicy() { Enabled = true, Days = 2 }; await service.SetPropertiesAsync(properties); do { await Delay(250); properties = await service.GetPropertiesAsync(); } while (!properties.Value.DeleteRetentionPolicy.Enabled); }
public static async Task EnableLoggingAsync(BlobServiceClient blobClient, CancellationToken cancellationToken) { BlobServiceProperties serviceProperties = await blobClient.GetPropertiesAsync(cancellationToken).ConfigureAwait(false); // Merge write onto it. BlobAnalyticsLogging loggingProperties = serviceProperties.Logging; if (!loggingProperties.Write) { // First activating. Be sure to set a retention policy if there isn't one. loggingProperties.Write = true; loggingProperties.RetentionPolicy = new BlobRetentionPolicy() { Enabled = true, Days = 7, }; // Leave metrics untouched await blobClient.SetPropertiesAsync(serviceProperties, cancellationToken).ConfigureAwait(false); } }
public async Task <string> UploadFile(string containerName, string fileName, IFormFile file, bool overwrite = true) { // Create the container if not exists and return a container client object BlobContainerClient containerClient = new BlobContainerClient(_connectionString, containerName); BlobServiceClient serviceClient = new BlobServiceClient(_connectionString); var props = (await serviceClient.GetPropertiesAsync()).Value; props.DefaultServiceVersion = "2019-07-07"; await serviceClient.SetPropertiesAsync(props); await containerClient.CreateIfNotExistsAsync(PublicAccessType.Blob); // Get a reference to a blob BlobClient blobClient = containerClient.GetBlobClient(fileName); if (!overwrite) { string newFileName; int count = 1; while (await blobClient.ExistsAsync()) { newFileName = $"{Path.GetFileNameWithoutExtension(fileName)}-{count++}{Path.GetExtension(fileName)}"; blobClient = containerClient.GetBlobClient(newFileName); } } // Open the file and upload its data var headers = new BlobHttpHeaders { ContentType = file.ContentType, ContentDisposition = file.ContentDisposition }; await using var uploadFileStream = file.OpenReadStream(); await blobClient.UploadAsync(uploadFileStream, headers); return(blobClient.Uri.AbsoluteUri); }