private CloudBlockBlob getBlob(Uri uri) { var storageAccount = CloudStorageAccount.Parse(DocConstants.Get().ConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); ICloudBlob blob = blobClient.GetBlobReferenceFromServer(uri); return(blob as CloudBlockBlob); }
private CloudBlobContainer getBlobContainer(string folderName, bool createIfNotExists = true, bool setPublic = true) { var storageAccount = CloudStorageAccount.Parse(DocConstants.Get().ConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer blobContainer = blobClient.GetContainerReference(folderName); if (createIfNotExists) { blobContainer.CreateIfNotExists(); } if (setPublic) { setPublicAccess(blobContainer); } return(blobContainer); }
/// <summary> /// Gets content of the blob /// </summary> /// <param name="fileName">The name of the blob, or the absolute URI to the blob</param> /// <param name="folderName">The name of the blob container</param> /// <param name="type">The type of the blob's content</param> /// <returns>Streams with blob's content</returns> public Stream Load(string fileName, string folderName, out string type) { var storageAccount = CloudStorageAccount.Parse(DocConstants.Get().ConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer blobContainer = blobClient.GetContainerReference(folderName); Stream file = null; type = string.Empty; string res = string.Format(PATH, folderName, fileName); var blob = blobContainer.GetBlockBlobReference(res); if (blob.Properties.Length > 0) { blob.FetchAttributes(); type = blob.Properties.ContentType; file = blob.OpenRead(); } return(file); }