private static void ReadSetMetaData(BlobClient _blob) { BlobProperties props = _blob.GetProperties(); IDictionary <string, string> metadata = props.Metadata; metadata.Add("Test", "Test"); _blob.SetMetadata(metadata); }
public async Task <bool> MoveBlob(IBlobContainer containerName, string sourcePath, string destinationPath) { var blobContainer = await GetBlobContainer(containerName); var destinationBlob = blobContainer.GetBlobClient(destinationPath); if (await destinationBlob.ExistsAsync()) { _logger.LogWarning( "Destination already exists while moving blob. Source: '{source}' Destination: '{destination}'", sourcePath, destinationPath); return(false); } var sourceBlob = blobContainer.GetBlobClient(sourcePath); if (!await sourceBlob.ExistsAsync()) { _logger.LogWarning( "Source blob not found while moving blob. Source: '{source}' Destination: '{destination}'", sourcePath, destinationPath); return(false); } // Lease the source blob for the copy operation // to prevent another client from modifying it. var lease = sourceBlob.GetBlobLeaseClient(); // Specifying -1 for the lease interval creates an infinite lease. await lease.AcquireAsync(TimeSpan.FromSeconds(-1)); try { await destinationBlob.StartCopyFromUriAsync(sourceBlob.Uri); // Get the destination blob's properties and log the progress BlobProperties destinationProperties = await destinationBlob.GetPropertiesAsync(); while (destinationProperties.CopyStatus == CopyStatus.Pending) { await Task.Delay(1000); _logger.LogInformation("Copy progress: {progress}", destinationProperties.CopyProgress); destinationProperties = await destinationBlob.GetPropertiesAsync(); } if (destinationProperties.CopyStatus != CopyStatus.Success) { return(false); } } finally { await lease.ReleaseAsync(); } await sourceBlob.DeleteAsync(); return(true); }