private static async Task <long> CopyFileAsync(string filePath, ILog log, BackupFolderBlobRepository backupFolderBlobRepository, BlobRequestOptionsHelper blobRequestOptionsHelper) { var fileBytes = new FileInfo(filePath).Length; var blobOutputLocation = GetBlobName(filePath); log.Info($"Copying {filePath} to {blobOutputLocation}, size: {fileBytes.ToPrettySize()}"); var cloudBlockBlob = backupFolderBlobRepository.CreateBlockBlob(blobOutputLocation, "image/jpg"); try { using (Stream source = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { source.Seek(0, SeekOrigin.Begin); await cloudBlockBlob.UploadFromStreamAsync(source, null, blobRequestOptionsHelper.Get(), null); } } catch (Exception ex) { log.Error(ex.Message); } return(fileBytes); }
public async Task <List <T> > ListAsync(string prefix = "") { ThrowWhenCloudBlobContainerDoesNotExist(); BlobContinuationToken continuationToken = null; var results = new List <T>(); do { var resultSegment = await Container.ListBlobsSegmentedAsync(prefix, true, BlobListingDetails.Metadata, 1000, continuationToken, _blobRequestOptionsHelper.Get(), null); foreach (var result in resultSegment.Results) { if (!(result is CloudBlockBlob blob)) { continue; } var item = await GetAsync(blob.Name); results.Add(item); } continuationToken = resultSegment.ContinuationToken; }while (continuationToken != null); return(results); }
/// <summary> /// Delete current blob container /// </summary> /// <returns>Return true on success, false if not found, throw exception on error.</returns> public async Task <bool> DeleteContainerAsync() { bool result; try { result = await Container.DeleteIfExistsAsync(null, _blobRequestOptionsHelper.Get(), null); Container = null; } catch (StorageException ex) { if (ex.RequestInformation.HttpStatusCode == 404) { return(false); } throw; } return(result); }