title: Upload an image to Azure Functions using HttpRequest from Postman
body: <p>I'm having a hard time getting an image uploaded to Azure Functions using <code>HttpRequest</code>. I'm specifically using <code>HttpRequest</code> because that's what the VS templates use. I've simplified the problem to a simple test case with Postman.</p>
  
  <p>Function:</p>
  
  <pre><code>[FunctionName("Function1")]
  public static async Task&lt;IActionResult&gt; Run(
      [HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequest req)
  {
      return new CreatedResult("", req.Form.Files[0].OpenReadStream());
  }
  </code></pre>
  
  <p>Postman:</p>
  
  <pre><code>Method: POST
  URL: [Function URL]
  Headers:
      Content-Type: multipart/form-data
  Body: binary with image selected
  </code></pre>
  
  <p>So what should happen is that I select a file to upload, I click "Send" to upload it to the Azure Function, which should automatically return the stream and display the picture in the Postman response.</p>
  
  <p>But when I call it from Postman, an exception is thrown when it tries to read the stream:</p>
  
  <blockquote>
    <p>"System.IO.InvalidDataException: Missing content-type boundary.\r\n   at Microsoft.AspNetCore.Http.Features.FormFeature.GetBoundary(MediaTypeHeaderValue contentType, Int32 lengthLimit)\r\n   at Microsoft.AspNetCore.Http.Features.FormFeature.InnerReadFormAsync(CancellationToken cancellationToken)\r\n   at Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm()\r\n   at Microsoft.AspNetCore.Http.Internal.DefaultHttpRequest.get_Form()\r\n   at [My code]"</p>
  </blockquote>
  
  <p>Now if I were to switch this to use <code>HttpRequestMessage</code> like the old Azure Function templates and use <code>req.Content.ReadAsStreamAsync()</code>, it works like a charm.</p>
  
  <p>But since the new templates use <code>HttpRequest</code>, this question is focused on the use of <code>HttpRequest</code> and its correct use. So how can I use <code>HttpRequest</code> to get this to work?</p>