public static Response <BlobContentInfo> Upload ( IAzureBlobClientBuilder clientBuilder, string blobName, string objectName, Stream streamToUpload, StorageTransferOptions transferOptions = default(StorageTransferOptions), EventHandler <AzureTransferProgressEventArgs> transferProgress = null, CancellationToken cancellationToken = default(CancellationToken) ) { if (clientBuilder == null) { throw new ArgumentNullException(nameof(clientBuilder)); } if (streamToUpload is null) { throw new ArgumentNullException(nameof(streamToUpload)); } var client = clientBuilder.GetBlobContainerClient(blobName).GetBlobClient(objectName); long streamLength = 0; if (streamToUpload.CanSeek) { streamLength = streamToUpload.Length; } return(client.Upload(streamToUpload, transferOptions: transferOptions, progressHandler: new AzureTransferProgressAdapter(streamLength, transferProgress), cancellationToken: cancellationToken)); }
public async ValueTask <List <FileSystemEntry> > EnumerateChildrenAsync(string filePath, CancellationToken cancellation = default) { filePath = filePath?.Replace('\\', '/').Trim('/') ?? ""; if (filePath.Length > 0) { filePath += "/"; } var client = _ClientBuilder.GetBlobContainerClient(_ContainerName); var pages = client.GetBlobsByHierarchyAsync(prefix: filePath, delimiter: "/").AsPages().ConfigureAwait(false); var files = new List <FileSystemEntry>(); await foreach (var page in pages) { foreach (var blob in page.Values) { if (!blob.IsBlob) { files.Add(new FileSystemEntry { Attributes = FileAttributes.Normal | FileAttributes.Directory, Size = 0, Name = blob.Prefix.Substring(filePath.Length).TrimEnd('/') }); } else { if (blob.Blob.Name.EndsWith('/')) { continue; } files.Add(new FileSystemEntry { Attributes = FileAttributes.Normal, ModificationDate = blob.Blob.Properties.LastModified?.DateTime, Size = blob.Blob.Properties.ContentLength ?? 0, Name = blob.Blob.Name.Substring(filePath.Length) }); } } } return(files); }