title: How to send multipart/form-data with PowerShell Invoke-RestMethod
body: <p>I'm trying to send a file via Invoke-RestMethod in a similar context as curl with the -F switch.  </p>
  
  <p>Curl Example</p>
  
  <pre><code>curl -F FileName=@"/path-to-file.name" "https://uri-to-post"
  </code></pre>
  
  <p>In powershell, I've tried something like this:</p>
  
  <pre><code>$uri = "https://uri-to-post"
  $contentType = "multipart/form-data"
  $body = @{
      "FileName" = Get-Content($filePath) -Raw
  }
  
  Invoke-WebRequest -Uri $uri -Method Post -ContentType $contentType -Body $body
  }
  </code></pre>
  
  <p>If I check fiddler I see that the body contains the raw binary data, but I get a 200 response back showing no payload has been sent.  </p>
  
  <p>I've also tried to use the -InFile parameter with no luck.</p>
  
  <p>I've seen a number of examples using a .net class, but was trying to keep this simple with the newer Powershell 3 commands.</p>
  
  <p>Does anyone have any guidance or experience making this work?</p>