title: How do I upload multiple files to Azure blob storage using an ID parameter as a container?
body: <p>I've created a storage account on Azure for uploading files to.  I am using KenoUI Async upload widget which allows multiple file uploads.  What I'd like to do is have the system create a container based on the passing in <code>Id</code> parameter if it doesn't already exist.</p>
  
  <p>I'm struggling with the actual upload part however, I'm not sure how to pass the enumerable files to the storage account.  Here is my code so far:</p>
  
  <pre><code>public ActionResult Async_Save(IEnumerable&lt;HttpPostedFileBase&gt; files, string id)
      {
          //Connect to Azure
          CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("my_AzureStorageConnectionString"));
  
          //Create Blob Client
          CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
  
          //Retrieve a reference to a container
          CloudBlobContainer blobContainer = blobClient.GetContainerReference("vehicle_" + id);
  
          try
          {
              // Create the container if it doesn't already exist
              blobContainer.CreateIfNotExists();
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.Message);
              Console.WriteLine(ex.InnerException);
  
          }
          foreach (var file in files)
          {
              //This doesn't seem right to me and it's where I'm struggling
              var fileName = Path.GetFileName(file.FileName);
              var physicalPath = Path.Combine(blobContainer, fileName);
              file.SaveAs(physicalPath);
          }
  
          // Return an empty string to signify success
          return Content("");
      }
  </code></pre>
  
  <p>What I've attempted to do is create a method that connects to my Azure storage account and:</p>
  
  <ol>
  <li>Check for the existence of a container with the same ID as the
  the parameter that's passed in, if it doesn't exist, create it.</li>
  <li>Upload the files to the existing or newly created directory and give them a prefix of the ID i.e. "_".</li>
  </ol>