title: Post multipart/form-data file from stream with HttpClient
body: <p><strong>The problem:</strong> Is it possible using httpclient to post a HttpPostedFileBase(only available in memory, not on disk.) to another endpoint?</p>
  <p><strong>What I've tried:</strong></p>
  <p>I have the following controller, we are posting in a file from our frontend and it binds to the file parameter.</p>
  <pre><code>public class HomeController : Controller
  {
      [System.Web.Http.HttpPost]
      public async Task&lt;string&gt; Index(HttpPostedFileBase file)
      {
          //file is not null here, everything works as it should.
  
          //Here im preparing a multipart/form-data request to my api endpoint
          var fileStreamContent = new StreamContent(file.InputStream);
          using (var client = new HttpClient())
          using (var formData = new MultipartFormDataContent())
          {
              formData.Add(fileStreamContent);
              var response = await client.PostAsync(&quot;http://restapi.dev/api/files/add&quot;, formData);
              var result = await response.Content.ReadAsStringAsync();
              return result;
          }
      }
  }
  </code></pre>
  <p>I need to pass this request on to another application that's not publicly available(so we can't post directly from the client)
  That controller looks like this:</p>
  <pre><code>[RoutePrefix(&quot;api/files&quot;)]
  public class FilesController : ApiController
  {
      [HttpPost]
      [Route(&quot;add&quot;)]
      public async Task&lt;HttpResponseMessage&gt; Add(HttpPostedFileBase file)
      {
          //This is the problem, file is always null when I post from my backend.
          var files = HttpContext.Current.Request.Files.Count &gt; 0 ? HttpContext.Current.Request.Files[0] : null;
          return Request.CreateResponse(HttpStatusCode.OK);
      }
  }
  </code></pre>
  <p><code>file</code> is always null, so are <code>files</code>.
  What am I missing? When I use postman and post directly to the API endpoint, it works. So im guessing that im doing something wrong in my <code>HomeController</code>?</p>