/// <summary> /// Upload the stream into the blob storage using the specified key. /// </summary> /// <param name="key">The key to uniquely locate and access the blob</param> /// <param name="stream">The stream to be uploaded</param> /// <returns></returns> public async Task UploadStreamBlobAsync(string key, Stream stream) { BlobStorageClientHelper.ParseKey(key, out string containerNameSuffix, out string blobName); ICloudBlob cloudBlob = await GetCloudBlockBlobReferenceAsync(containerNameSuffix, blobName); await cloudBlob.UploadFromStreamAsync(stream); }
/// <summary> /// Download the blob from the storage using key. /// </summary> /// <param name="key">The key to uniquely locate and access the blob</param> /// <returns>A downloaded stream</returns> public async Task <Stream> DownloadStreamAsync(string key) { BlobStorageClientHelper.ParseKey(key, out string containerNameSuffix, out string blobName); ICloudBlob cloudBlob = await GetCloudBlockBlobReferenceAsync(containerNameSuffix, blobName); Stream targetStream = new MemoryStream(); await cloudBlob.DownloadToStreamAsync(targetStream); targetStream.Position = 0; return(targetStream); }