title: Download Multiple Uploaded Files
body: <p>I uploaded multiple files as bytes into database table and how to download files as zip now?  My code as below:
  View:</p>
  <pre><code>@using (Html.BeginForm(Html.BeginForm(&quot;upload&quot;, &quot;Home&quot;, FormMethod.Post, new { @id = &quot;form&quot;, enctype = &quot;multipart/form-data&quot; })))
          {
              &lt;input type=&quot;file&quot; multiple=&quot;multiple&quot; name=&quot;files&quot; id=&quot;files&quot; /&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;div class=&quot;col-md-offset-2 col-md-10&quot;&gt;
                      &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; class=&quot;btn btn-default&quot; /&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          }
  </code></pre>
  <p>controller:</p>
  <pre><code>    public FileContentResult GetFile(int id)
      {
          
          SqlDataReader rdr; byte[] fileContent = null;
          string mimeType = &quot;&quot;; string fileName = &quot;&quot;;
          string constr = WebConfigurationManager.ConnectionStrings[&quot;DbContextModel&quot;].ConnectionString;
  
          using (SqlConnection con = new SqlConnection(constr))
          {
              var qry = &quot;SELECT * FROM myTable WHERE ID = @ID&quot;;
              var cmd = new SqlCommand(qry, con);
              cmd.Parameters.AddWithValue(&quot;@ID&quot;, id);
              con.Open();
              rdr = cmd.ExecuteReader();
              if (rdr.HasRows)
              {
                  rdr.Read();
                  fileContent = (byte[])rdr[&quot;Attachments&quot;];
  
              }
          }
          return File(fileContent, &quot;application/zip&quot;, &quot;download.zip&quot;);
          
      }
  </code></pre>
  <p>Model:</p>
  <pre><code>  public partial class myTable
   {
    public int id {get;set;}
    public byte[] Attachments { get; set; }
    }
  </code></pre>
  <p>The download.zip file cannot be opened. &quot;The compressed zipped folder is invalid&quot;. Please advise. Thanks in advance.</p>
  <p>upload function:</p>
  <pre><code>...
       byte[] bytes = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
              MemoryStream target = new MemoryStream();
              foreach (var file in files)
              {
                  if (file.ContentLength &gt; 0)
                  { 
                       file.InputStream.CopyTo(target);
                      bytes = target.ToArray();
                 
                  }
                  
              }
  </code></pre>