title: .NET core 3.1 C# nswag file upload
body: <p>I'm trying to upload a file to a C# application that is based on a Openapi specification. NSwag is used to generate the most of the C# code and I override the functions of the base class that is generated.</p>
  <p>The Openapi specification that I have at this point is the following (relevant part):</p>
  <pre class="lang-yaml prettyprint-override"><code>/upload:
      post:
        operationId: uploadFile
        tags:
          - file
        requestBody:
          description: The file to be uploaded
          required: True
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        responses:
          '200':
            description: Returns a test message for now
            content:
              text/plain:
                schema:
                  type: string
          default:
            description: Unexpected error
            content:
              application/json:
                schema:
                  $ref: &quot;#/components/schemas/ErrorResponse&quot;
  </code></pre>
  <p>with the ErrorResponse scheme at the components section of the file (not included in the code block).</p>
  <p>The generated code is the following:</p>
  <pre class="lang-cs prettyprint-override"><code>[System.CodeDom.Compiler.GeneratedCode(&quot;NSwag&quot;, &quot;13.4.2.0 (NJsonSchema v10.1.11.0 (Newtonsoft.Json v12.0.0.0))&quot;)]
      [Microsoft.AspNetCore.Mvc.Route(&quot;api/test&quot;)]
      public abstract class FileControllerBase : Microsoft.AspNetCore.Mvc.Controller
      {
          /// &lt;param name=&quot;body&quot;&gt;The file to be uploaded&lt;/param&gt;
          /// &lt;returns&gt;Returns a test message for now&lt;/returns&gt;
          [Microsoft.AspNetCore.Mvc.HttpPost, Microsoft.AspNetCore.Mvc.Route(&quot;upload&quot;)]
          public abstract System.Threading.Tasks.Task&lt;string&gt; UploadFile(Microsoft.AspNetCore.Http.IFormFile body, System.Threading.CancellationToken cancellationToken);
      
      }
  </code></pre>
  <p>And the override function (in the inherited class):</p>
  <pre class="lang-cs prettyprint-override"><code>public override async System.Threading.Tasks.Task&lt;string&gt; UploadFile(Microsoft.AspNetCore.Http.IFormFile body, System.Threading.CancellationToken cancellationToken) {
  
              //body parameter is always zero...
              await Task.Delay(10); // To &quot;mislead&quot; the async in the function definition, is needed in the real application
              if (body != null) {
                  Console.WriteLine(&quot;Not Null&quot;);
              } else {
                  Console.WriteLine(&quot;Null&quot;); // is always the outcome of the request
              }
              return &quot;result&quot;; //return random string
          }
  </code></pre>
  <p>Other useful information:</p>
  <ul>
  <li>NSwag version: 13.4.2</li>
  <li>Openapi version: 3.0.3</li>
  <li>Using the swagger UI to test the endpoints and verifying with wireshark that the request is properly send over with the data.</li>
  </ul>
  <p>Now the question is, am I doing something wrong here? I cannot seem to get this working and I have tried all kinds of approaches to define the endpoint (using multipart/form-data, ...). Also tried it with postman to see if the issue is within Swagger UI, but the result is the same.</p>