title: How can I upload a file and form data using Flurl?
body: <p>I'm trying to upload a file with body content. Is <code>PostMultipartAsync</code> the only way? </p>
  
  <p>On my C# backend code I have this:</p>
  
  <pre><code>var resource = FormBind&lt;StorageFileResource&gt;();
  var file = Request.Files.First().ToPostedFile();
  </code></pre>
  
  <p><code>FormBind</code> reads data from the request and fills the object.</p>
  
  <p>By using <code>PostMultipartAsync</code> I know it should start like this:</p>
  
  <p><code>.PostMultipartAsync((mp) =&gt; { mp.AddFile(name, stream, name)})</code>, but I can't figure out how to add the object. Do you have any ideas on that?</p>
  
  <p>This is my current try:</p>
  
  <pre><code>public static async Task&lt;T&gt; PostFileAsync&lt;T&gt;(string url, object data, string name, Stream stream, object queryString = null)
      where T : class
  {
      return await HandleRequest(async () =&gt; queryString != null
          ? await url
              .SetQueryParams(queryString)
              .SetClaimsToken()
              .PostMultipartAsync((mp) =&gt; { mp.AddFile(name, stream, name)})
              .ReceiveJson&lt;T&gt;()
          : await url
              .SetClaimsToken()
              .PostMultipartAsync((mp) =&gt; mp.AddFile(name, stream, name))
              .ReceiveJson&lt;T&gt;());
  }
  </code></pre>
  
  <p>Current request being made by the front end:</p>
  
  <p><a href="https://i.stack.imgur.com/kEHHo.png" rel="noreferrer"><img src="https://i.stack.imgur.com/kEHHo.png" alt="enter image description here"></a></p>