title: Azure blobs how to await for blob creation before proceeding?
body: <p>I am using NodeJS and the azure storage sdk, I am having an issue that the files I am uploading to my blobs are being created as 0kb files unless I add an intermediary function to delay it so that the blob is created before the upload happens. I get the same results when uploading as a stream or as a local file from the azure-storage sdk.</p>
  
  <p>I have the following function:</p>
  
  <pre><code>async function uploadToBlob(localFilePath) {
  
  
          //ACTIVATE CREDENTIALS AND CONTAINER
      const credentials = new SharedKeyCredential(STORAGE_ACCOUNT_NAME, ACCOUNT_ACCESS_KEY);
      const pipeline = StorageURL.newPipeline(credentials);
      const serviceURL = new ServiceURL(`https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net`, pipeline);
      const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);  
      const aborter = Aborter.timeout(30 * ONE_MINUTE);
  
      //UPLOAD IMAGE
      var blobName = localFilePath.substring(localFilePath.lastIndexOf('/') + 1 );
      var fullBlobName = category + "/" + subcategory + "/" + blobName;
      var blobURL = await BlockBlobURL.fromContainerURL(containerURL, fullBlobName);
  
      await uploadImage(aborter, containerURL, localFilePath, blobURL)
  
  
  }
  </code></pre>
  
  <p>where I get the blobURL var by doing an await on BlockBlobURL.fromContainerURL
  and as you can see has an await on it and there is also an await on the call to uploadImage.</p>
  
  <p>Then here is the function that is called and that calls the uploadFileToBlockBlob from azures sdk:</p>
  
  <pre><code>//UPLOAD IMAGE NO-STREAM
  async function uploadImage(aborter, containerURL, filePath, blobURL, blobName) {
      try {
          filePath = path.resolve(filePath);
  
           //THIS LINE MAKES IT WORK
          await showBlobNames(aborter, containerURL);
  
          addToDB(blobName, blobURL.url);
  
  
          console.log("Calling uploadFileToBlockBlob with filePath: " + filePath + 
                      " and blobURL: "+ blobURL.url)
          return await uploadFileToBlockBlob(aborter, filePath, blobURL);
      }
      catch(err) {
          console.log(err)
      }
  }
  </code></pre>
  
  <p>In this last function I added </p>
  
  <pre><code>await showBlobNames(aborter, containerURL);
  </code></pre>
  
  <p>and that made it work.</p>
  
  <p>It seems like before that the file was being uploaded before the blob was created and the images were being uploaded with the right name and into the blob but as 0kb files, and adding this function delays it so that the Blob can be created.</p>
  
  <p>I don't understand why the previous awaits don't make the upload wait till the blob is created.  I also tried putting the upload call inside a callback function but so it would be executed when the blob is created but doesnt seem to be supported (doesnt call the callback function)</p>
  
  <p>I have it working adding the call to showBlobNames but I feel like my code shouldnt have to rely on this and I want to learn why the await's arent working.</p>
  
  <p>Thank You</p>