private async void UploadBlob(CloudBlobContainer container, StorageFile file, string fileName, int fileId, long fileSize) { using (var fileStream = await file.OpenStreamForReadAsync()) { // Retrieve reference to a blob CloudBlockBlob blob = container.GetBlockBlobReference(fileName); AzureProgressStream progressStream = new AzureProgressStream(fileStream); progressStream.ProgressChanged += pstream_ProgressChanged; progressStream.SetLength(fileSize); progressStream.FileId = fileId; IInputStream inputStream = WindowsRuntimeStreamExtensions.AsInputStream(progressStream); await blob.UploadFromStreamAsync(inputStream); } }
private async void DownloadBlob(CloudBlobContainer container, string fileName, int fileId, long fileSize) { StorageFolder pictureFolder = KnownFolders.PicturesLibrary; StorageFile file = await pictureFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); using (var fileStream = await file.OpenStreamForWriteAsync()) { // Retrieve reference to a blob CloudBlockBlob blob = container.GetBlockBlobReference(fileName); Stream stream = new MemoryStream(); AzureProgressStream progressStream = new AzureProgressStream(stream); progressStream.ProgressChanged += pstream_ProgressChanged; progressStream.SetLength(fileSize); progressStream.FileId = fileId; IOutputStream outputStream = WindowsRuntimeStreamExtensions.AsOutputStream(progressStream); await blob.DownloadToStreamAsync(outputStream); stream.Position = 0; stream.CopyTo(fileStream); fileStream.Flush(); } }