Forum Discussion

bbinckes's avatar
bbinckes
Occasional Visitor
5 years ago

Swagger UI failing to execute multiple file upload (open api 3.01)

I have a .aspnet core 3.1 project that implements swagger UI (5.00).  One of the API methods posts multiple images,

 

        [HttpPost("images", Name = "PostImages")]
        public async Task<IActionResult> Images([FromForm] IEnumerable<IFormFile> files)
        {

I am implementing an IOperationFilter to rebake the schema.

 if (operation.OperationId != "PostImages")
            {
                return;
            }

            var properties = new Dictionary<string, OpenApiSchema>();
            var openApiSchema = new OpenApiSchema
            {
                
                Type = "array",
                Items = new OpenApiSchema
                {
                    Type = "string",
                    Format = "binary",
                    Description = "Multiple File Upload"
                }
                
            };
            properties.Add("files", openApiSchema);

            operation.RequestBody.Content["multipart/form-data"].Schema.Properties = properties;

 

Where the json looks like this,

"/api/Upload/images": {
      "post": {
        "tags": [
          "Upload"
        ],
        "operationId": "PostImages",
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "description": "Multiple File Upload",
                      "format": "binary"
                    }
                  }
                }
              },
              "encoding": {
                "files": {
                  "contentType": "image/png",
                  "style": "form"
                }
              }
            }
          }
        },

 

Seems like all of this is correct but when breaking in the method I get no files.  My dev tools show the request body as,

files: [object File],[object File]

Throw me a bone someone.  This is driving me crazy.

Thank you