title: createBlockBlob and commitBlobBlocks create empty files in BlobStorage
body: <p>I'm developing a web app that can upload large file into the Azure Blob Storage.</p>
  
  <p>As a backend, I am using Windows Azure Mobile Services (the web app will generate contents for mobile devices) in nodeJS.</p>
  
  <p>My client can successfully send chunks of data to the backend, everything looks fine but, at the end, the uploaded file is empty. The data upload has been prepared by following this tutorial: it works perfectly when the file is small enough to be uploaded in a single requests. The process fails when the file needs to be broken in chunks. It uses the ReadableStreamBuffer from the tutorial.</p>
  
  <p>Can somebody help me?</p>
  
  <p>Here the code:</p>
  
  <p><strong>Back-end : createBlobBlockFromStream</strong></p>
  
  <pre><code>[...]
              //Get references
              var azure = require('azure');
              var qs = require('querystring');
              var appSettings = require('mobileservice-config').appSettings;
  
              var accountName = appSettings.STORAGE_NAME;
              var accountKey = appSettings.STORAGE_KEY;
              var host = accountName + '.blob.core.windows.net';
  
              var container = "zips";
              //console.log(request.body);
              var blobName = request.body.file;
              var blobExt = request.body.ext;               
              var blockId = request.body.blockId;
              var data = new Buffer(request.body.data, "base64");
              var stream = new ReadableStreamBuffer(data);
              var streamLen = stream.size();
  
              var blobFull = blobName+"."+blobExt;
              console.log("BlobFull: "+blobFull+"; id: "+blockId+"; len: "+streamLen+"; "+stream);
              var blobService = azure.createBlobService(accountName, accountKey, host);
              //console.log("blockId: "+blockId+"; container: "+container+";\nblobFull: "+blobFull+"streamLen: "+streamLen);
              blobService.createBlobBlockFromStream(blockId, container, blobFull, stream, streamLen,
                  function(error, response){
                      if(error){
                          request.respond(statusCodes.INTERNAL_SERVER_ERROR, error);
                      } else {
                          request.respond(statusCodes.OK, {message : "block created"});
                      }
                  });
  [...]
  </code></pre>
  
  <p><strong>Back-end: commitBlobBlock</strong></p>
  
  <pre><code>[...]
              var azure = require('azure');
              var qs = require('querystring');
              var appSettings = require('mobileservice-config').appSettings;
  
              var accountName = appSettings.STORAGE_NAME;
              var accountKey = appSettings.STORAGE_KEY;
              var host = accountName + '.blob.core.windows.net';
  
              var container = "zips";
              var blobName = request.body.file;
              var blobExt = request.body.ext;
              var blobFull = blobName+"."+blobExt;
              var blockIdList = request.body.blockList;
              console.log("blobFull: "+blobFull+"; blockIdList: "+JSON.stringify(blockIdList));
              var blobService = azure.createBlobService(accountName, accountKey, host);
              blobService.commitBlobBlocks(container, blobFull, blockIdList, function(error, result){
                  if(error){
                      request.respond(statusCodes.INTERNAL_SERVER_ERROR, error);
                  } else {
                      request.respond(statusCodes.OK, result);
                      blobService.listBlobBlocks(container, blobFull)
                  }
              });
  [...]
  </code></pre>
  
  <p>The second method returns the correct list of blockId, so I think that the second part of the process works fine. I think that it is the first method that fails to write the data inside the block, as if it creates some empty blocks.</p>
  
  <p>In the client-side, I read the file as an ArrayBuffer, by using the FileReader JS API.</p>
  
  <p>Then I convert it in a Base4 encoded string by using the following code. This approach works perfectly if I create the blob in a single call, good for small files.</p>
  
  <pre><code>[...]
  //data contains the ArrayBuffer read by the FileReader API
  var requestData = new Uint8Array(data);
  
  var binary = "";
  for (var i = 0; i &lt; requestData.length; i++) {
      binary += String.fromCharCode( requestData[ i ] );
  }
  [...]
  </code></pre>
  
  <p>Any idea?</p>
  
  <p>Thank you,
      Ric</p>