GlobalDemo.DAL.Azure.StorageRepository.GetBlob C# (CSharp) Method

GetBlob() public method

public GetBlob ( string containerName, string fileName ) : Task
containerName string
fileName string
return Task
        public async Task<MemoryStream> GetBlob(string containerName, string fileName)
        {
            
            var client = _account.CreateCloudBlobClient();
            var container = client.GetContainerReference(containerName);
            var blockBlob = container.GetBlockBlobReference(fileName);
            var ret = new MemoryStream();
            await blockBlob.DownloadToStreamAsync(ret);

            return ret;
        }

Usage Example

示例#1
0
        internal static async Task CreateThumbnailAsync(StorageRepository repo, string fileName, TextWriter log)
        {
            using (var memStream = await repo.GetBlob(StorageConfig.PhotosBlobContainerName, fileName))
            {
                MemoryStream thumbnail = null;
                try
                {
                    thumbnail = PhotoEditor.ProcessImage(memStream);
                    await repo.UploadBlobAsync(thumbnail, StorageConfig.ThumbnailsBlobContainerName, fileName);
                }
                catch (Exception oops)
                {
                    await log.WriteAsync(oops.Message);
                    throw oops;
                }
                finally
                {
                    if (null != thumbnail)
                    {
                        thumbnail.Dispose();
                    }
                }

            }
        }