title: Azure blob storage V12 - Example of using specialized class BlockBlobStorage
body: <p>I have hard time with new version of <a href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/storage/Azure.Storage.Blobs" rel="nofollow noreferrer">Azure Storage Blobs client library for .NET</a>. </p>
  
  <p>What I need is create stream where I can write data and let's say, after stream reach size of 4MB, then I need to upload it. I found <a href="https://docs.microsoft.com/en-us/dotnet/api/azure.storage.blobs.specialized.blockblobclient?view=azure-dotnet" rel="nofollow noreferrer">BlockBlobClient</a>. There are two methods CommitBlockListAsync and StageBlockAsync. This methods looks like what I need, but I can't find some examples of usage.</p>
  
  <p>Do you know about some scenario similar to my needs? Or can you someone help me understand this client?</p>
  
  <p>Something like this I need, Every 4MB stage, clear stream and continue to write:</p>
  
  <pre><code>public class MyStreamWrapper : Stream
  {
      readonly BlockBlobClient _blockBlobClient;
      readonly Stream _wrappedStream;
      bool _isCommited;
      readonly List&lt;string&gt; _blockIds;
  
      public MyStreamWrapper (BlockBlobClient blockBlobClient)
      {
          _wrappedStream = new MemoryStream();
          _blockBlobClient = blockBlobClient;
          _isCommited = false;
          _blockIds = new List&lt;string&gt;();
      }
  
      public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
      {
          if ((_wrappedStream.Length + buffer.Length) / 1024 &gt; 4) // check size if 
          {
             int byteCount = (int)(_wrappedStream.Length - buffer.Length);
             if (byteCount &gt; 0)
             {
                _wrappedStream.Write(buffer, offset, byteCount);
                offset += byteCount;
             }
  
             string base64Id = Convert.ToBase64String(buffer);
             _blockIds.Add(base64Id);
             _blockBlobClient.StageBlock(base64Id, _wrappedStream);
             _wrappedStream.Flush();
          }
  
          await _wrappedStream.WriteAsync(buffer, offset, count, cancellationToken);
      }
  
  }
  </code></pre>