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

UploadBlobAsync() public method

public UploadBlobAsync ( MemoryStream stream, string containerName, string fileName ) : Task
stream System.IO.MemoryStream
containerName string
fileName string
return Task
        public async Task UploadBlobAsync(MemoryStream stream, string containerName, string fileName)
        {
            var client = _account.CreateCloudBlobClient();
            var container = client.GetContainerReference(containerName);
            var blockBlob = container.GetBlockBlobReference(fileName);
            await blockBlob.UploadFromStreamAsync(stream);
        }
    }

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();
                    }
                }

            }
        }