title: Upload a file from ZipOutputStream to MVC 3 action
body: <p>I am using <strong>ZipOutputStream</strong> from <strong>SharpZipLib</strong> and I wish to upload the zipped contents it creates directly to my MVC post action.  I am successfully getting it to post however the parameter of my action method has null as the posted data when it gets to my MVC action.</p>
  
  <p>Here is my Test code I'm using to test this out:</p>
  
  <pre><code>    public void UploadController_CanUploadTest()
      {
          string xml = "&lt;test&gt;xml test&lt;/test&gt;"
          string url = "http://localhost:49316/Api/DataUpload/Upload/";
  
          WebClient client = new WebClient();
  
          var cc= new CredentialCache();
          cc.Add(new Uri(url),
                "Basic", 
                new NetworkCredential("Testuser", "user"));
  
          client.Credentials = cc;
  
          string _UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
          client.Headers.Add(HttpRequestHeader.UserAgent, _UserAgent);
          client.Headers["Content-type"] = "application/x-www-form-urlencoded";
  
          using (var stream = client.OpenWrite(url, "POST"))
          {
              Zipped zip = new Zipped(stream, Encoding.UTF8, false);
  
              FileContent content = new FileContent("Upload", xml);
  
              var uploads = new List&lt;FileContent&gt;();
              uploads.Add(content);
  
              zip.Compress(uploads);
  
              stream.Flush();
              stream.Close();
          }
      }
  </code></pre>
  
  <p>This is my zipped class wrapper:</p>
  
  <pre><code>    public class Zipped : ICompression, IDisposable
  {
      private Stream _stream = null;
      private bool _closeStreamOnDispose = true;
      private Encoding _encoding;
  
      public Zipped()
          : this(new MemoryStream())
      {
  
      }
  
      public Zipped(Stream stream)
          : this(stream, Encoding.UTF8, true)
      {
      }
  
      public Zipped(Stream stream, Encoding encoding)
          : this(stream, encoding, true)
      {
      }
  
      public Zipped(Stream stream, Encoding encoding, bool closeStreamOnDispose)
      {
          _stream = stream;
          _closeStreamOnDispose = closeStreamOnDispose;
          _encoding = encoding;
      }
  
      public Stream Compress(IList&lt;FileContent&gt; dataList)
      {
          ZipOutputStream outputStream = new ZipOutputStream(_stream);
          outputStream.SetLevel(9);
  
          foreach (var data in dataList)
          {
              ZipEntry entry = new ZipEntry(data.Name);
              entry.CompressionMethod = CompressionMethod.Deflated;
  
              outputStream.PutNextEntry(entry);
  
              byte[] dataAsByteArray = _encoding.GetBytes(data.Content);
  
              outputStream.Write(dataAsByteArray, 0, dataAsByteArray.Length);
              outputStream.CloseEntry();
          }
  
          outputStream.IsStreamOwner = false;
          outputStream.Flush();
          outputStream.Close();
  
          return _stream;
      }
  
      public List&lt;FileContent&gt; DeCompress()
      {
          ZipInputStream inputStream = new ZipInputStream(_stream);
          ZipEntry entry = inputStream.GetNextEntry();
  
          List&lt;FileContent&gt; dataList = new List&lt;FileContent&gt;();
  
          while(entry != null)
          {
              string entryFileName = entry.Name;
  
              byte[] buffer = new byte[4096];     // 4K is optimum
  
              // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
              // of the file, but does not waste memory.
              // The "using" will close the stream even if an exception occurs.                
              using (MemoryStream tempMemoryStream = new MemoryStream())
              {
                  StreamUtils.Copy(inputStream, tempMemoryStream, buffer);
  
                  string copied = _encoding.GetString(tempMemoryStream.ToArray());
                  dataList.Add(new FileContent(entry.Name, copied));
              }
  
              entry = inputStream.GetNextEntry();
          }
  
          return dataList;
  
      }
  
      public void Dispose()
      {
          if(_closeStreamOnDispose)
              _stream.Dispose();
      }
  </code></pre>
  
  <p>Here is my simple MVC action:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Upload(HttpPostedFileBase uploaded)
      {
          // uploaded is null at this point
      }
  </code></pre>