cancel
Showing results for 
Search instead for 
Did you mean: 

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

Highlighted
Occasional Visitor

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;

2020-02-17_17-48-31.png

 

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

 

1 REPLY 1
Highlighted
Moderator

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

Hi @bbinckes,

 

There's a known issue with multiple file upload:

https://github.com/swagger-api/swagger-ui/issues/4600


Helen Kosova
SmartBear Documentation Team Lead
________________________

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors
Top Kudoed Posts