/// <summary> /// Gets documents with in a reference (directory) /// </summary> /// <param name="reference"></param> /// <returns></returns> public async Task <IList <Document> > GetItems(string reference = null) { var cloudBlobContainer = BlobFactory.GetBlobContainer(ContainerName, DocumentBlogConnectionString); BlobContinuationToken token = null; var results = new List <IListBlobItem>(); do { BlobResultSegment result; if (reference != null) { var container = cloudBlobContainer.GetDirectoryReference(reference); result = await container.ListBlobsSegmentedAsync(token); } else { result = await cloudBlobContainer.ListBlobsSegmentedAsync(token); } results.AddRange(result.Results); token = result.ContinuationToken; } while (token != null); return(ConvertToDocuments(results)); }
/// <summary> /// Gets a document from the blob store and sends back the binary ready for download. /// </summary> /// <param name="filename">Name of file to be downloaded</param> /// <returns>Data</returns> public async Task <MemoryStream> GetDocument(string filename) { var cloudBlobContainer = BlobFactory.GetBlobContainer(ContainerName, DocumentBlogConnectionString); CloudBlockBlob blockBlob = cloudBlobContainer.GetBlockBlobReference(filename); MemoryStream memStream = new MemoryStream(); await blockBlob.DownloadToStreamAsync(memStream); return(memStream); }
public async Task <MemoryStream> GetPhoto(string emailaddress) { var cloudBlobContainer = BlobFactory.GetBlobContainer(ContainerName, PhotoBlobConnectionString); CloudBlockBlob blockBlob = cloudBlobContainer.GetBlockBlobReference(emailaddress.ToLower() + ".jpg"); if (!await blockBlob.ExistsAsync()) { return(null); } MemoryStream memStream = new MemoryStream(); await blockBlob.DownloadToStreamAsync(memStream); return(memStream); }
private async Task <List <IListBlobItem> > GetAllDocuments() { var cloudBlobContainer = BlobFactory.GetBlobContainer(ContainerName, DocumentBlogConnectionString); BlobContinuationToken token = null; var results = new List <IListBlobItem>(); do { var response = await cloudBlobContainer.ListBlobsSegmentedAsync("", true, BlobListingDetails.None, null, token, null, null); results.AddRange(response.Results); token = response.ContinuationToken; } while (token != null); return(results); }