question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OAS 3: Support for uploading an array of files in multipart requests

See original GitHub issue

Swagger UI 3.16.0 added support for binary file upload using multipart requests. It works if a multipart request uses files as specific named fields, but doesn’t work if the request uses an array of files.

Q&A (please complete the following information)

  • OS: Windows 7
  • Browser: Chrome 66
  • Method of installation: http://petstore.swagger.io, also using a local copy of Editor.
  • Swagger-UI version: 3.16.0
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

This spec is based on an example from the OpenAPI 3.0.1 Specification:

openapi: 3.0.1
info:
 title: Multiple file upload test
 version: 0.0.0
servers:
  - url: http://httpbin.org
paths:
 /post:
   post:
     requestBody:
       content:
         multipart/form-data:
           # This works:
           # schema:
           #   type: object
           #   properties:
           #     upload:
           #       type: string
           #       format: binary
           
           # This doesn't work:
           schema:
             type: object
             properties:
               # The property name 'file' will be used for all files.
               file:
                 type: array
                 items:
                   type: string
                   format: binary
     responses:
       '200':
         description: OK

Is your feature request related to a problem?

Yes, clicking “try it out” shows “😱 Could not render this component, see the console.” The console errors are:

TypeError: Cannot read property 'inferSchema' of undefined
    at t.value (swagger-ui.js:1)
    at t.render (swagger-ui.js:1)
    at u._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:796)
    at u._renderValidatedComponent (ReactCompositeComponent.js:819)
    at u.performInitialMount (ReactCompositeComponent.js:359)
    at u.mountComponent (ReactCompositeComponent.js:255)
    at Object.mountComponent (ReactReconciler.js:43)
    at u.performInitialMount (ReactCompositeComponent.js:368)
    at u.mountComponent (ReactCompositeComponent.js:255)
    at Object.mountComponent (ReactReconciler.js:43)

TypeError: Cannot read property 'inferSchema' of undefined
    at t.value (swagger-ui.js:1)
    at t.render (swagger-ui.js:1)
    at u._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:796)
    at u._renderValidatedComponent (ReactCompositeComponent.js:819)
    at u._updateRenderedComponent (ReactCompositeComponent.js:743)
    at u._performComponentUpdate (ReactCompositeComponent.js:721)
    at updateComponent (ReactCompositeComponent.js:642)
    at u.receiveComponent (ReactCompositeComponent.js:544)
    at Object.receiveComponent (ReactReconciler.js:122)
    at u._updateRenderedComponent (ReactCompositeComponent.js:751)

😱

Describe the solution you’d like

Clicking “try it out” presents a form where we can upload multiple files.

Describe alternatives you’ve considered

N/a

Additional context

This is (sort of) related to #3641 “OAS 3.0 Support Backlog”.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:83
  • Comments:40 (10 by maintainers)

github_iconTop GitHub Comments

26reactions
mansuryancommented, Aug 15, 2019

Is there any news??? The same problem for me

15reactions
hkosovacommented, Aug 6, 2018

@cedric-c84-eu It looks like file array upload is not implemented yet. The file inputs are displayed now, but the actual request contains the string [object File] instead of the file contents.

curl -X POST "http://httpbin.org/post" -H "accept: */*" -H "Content-Type: multipart/form-data" -F "file=[object File],[object File]"
POST http://httpbin.org/post
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryIk1aWkovTmf7LSJX

------WebKitFormBoundaryIk1aWkovTmf7LSJX
Content-Disposition: form-data; name="file"

[object File],[object File]
------WebKitFormBoundaryIk1aWkovTmf7LSJX--
Read more comments on GitHub >

github_iconTop Results From Across the Web

Multipart Requests - Swagger
OAS 3 This guide is for OpenAPI 3.0. ... File uploads typically use the multipart/form-data media type, ... Primitive or array of primitives,...
Read more >
Uploading an array of MultipartFile objects using Swagger-UI ...
1. You need Springfox 3.0 or springdoc-openapi to upload arrays of files - these versions generate OpenAPI 3.0 definitions (where file arrays ......
Read more >
File Upload via Swagger - codeburst
The Swagger UI generates a file input field array which allows us to add or remove files before sending the request. UPDATE 06/19/2020:...
Read more >
File Upload via Multipart Requests - API Microgateway 310
The following example shows how to upload a file via multipart request in OAS3. If you are using an OAS2 API definition, please...
Read more >
OpenAPI Specification v3.0.3 | Introduction, Definitions, & More
The OpenAPI Specification (OAS) defines a standard, ... for File Uploads; 4.7.14.4 Support for x-www-form-urlencoded Request Bodies ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found