Repository navigation
OAS 3: Support for uploading an array of files in multipart requests #4600
Copy link
Copy link
Closed
Description
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: OKIs 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".
Reactions are currently unavailable

Activity
tuxedo0801 commentedon Jul 24, 2018
I'm having the same issue here on swaggerhub.
Any updat on this?
cedric-jonas-kisters commentedon Aug 4, 2018
Works for me actually.
hkosova commentedon 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.malutanpetronel commentedon Oct 31, 2018
I dd in laravel the result of this and get ...characters">[object File],[object File]"...
bleuscyther commentedon Dec 12, 2018
same as @malutanpetronel
lcahlander commentedon Jan 28, 2019
It is failing in curlify.js
curlify is not taking the array into account
default-writer commentedon May 2, 2019
probably it is better to take a blob
mansuryan commentedon Aug 15, 2019
Is there any news???
The same problem for me
0s3v3n0 commentedon Aug 22, 2019
Hello is there any progress ? its opened more than year ...
The same problem for me
webron commentedon Aug 22, 2019
As always, PRs are welcome.
jmfernandez commentedon Sep 30, 2019
It will be more than welcome when it is ready
Darkzarich commentedon Oct 1, 2019
I did everything following documentation and it did work and did send files like this:
However, my backend app (Node.js and Multer for uploading files) was unable to see it.
I tried to upload files with javascript using FormData class like this:
And it worked as expected.
I'm not sure if this header swagger ui sends is right or wrong but I think this is the reason. Sending single files works perfectly
14 remaining items
dfeinzeig commentedon May 21, 2020
I just tried PR #5999 but still does not work. The input type is now text instead of file, so you can't choose files. If I change it to file it just posts a list of filenames, but no files.
hkosova commentedon May 21, 2020
@anzoman @dfeinzeig Uploading arrays of files is not supported yet.
dfeinzeig commentedon May 21, 2020
@hkosova , can you point me at any relevant parts of the code that would need to be updated to support it?
hkosova commentedon May 21, 2020
@dfeinzeig
#4600 (comment)
webhacking commentedon May 25, 2020
Any news ?
tim-lai commentedon May 27, 2020
@hkosova @anzoman @dfeinzeig @webhacking multiple file upload using OAS3.0 and arrays is now properly supported in the most recent SwaggerClient release (v3.25.4). Here's my sample definition:
{ "openapi": "3.0.0", "servers": [ { "url": "http://localhost:3300/api/v1" } ], "info": { "version": "1", "title": "MULTI PART TEST - OAS3", "description": "" }, "paths": { "/land/content/ViewOfAuthOwner": { "post": { "summary": "", "requestBody": { "content": { "multipart/form-data": { "schema": { "type": "object", "properties": { "hhlContent:sort": { "description": "", "default": "id", "type": "string", "enum": [ "id", "title" ] }, "hhlContent:order": { "description": "", "default": "desc", "type": "string", "enum": [ "asc", "desc" ] }, "email[]": { "description": "The list of emails.", "type": "array", "items": { "type": "string" } } } }, "encoding": { "style": "pipeDelimited", "explode": false } } } }, "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "type": "object" } } } } } } }, "/land/content/uploadImage": { "post": { "summary": "upload image(s)", "requestBody": { "content": { "multipart/form-data": { "schema": { "type": "object", "properties": { "imageId": { "description": "", "default": "id", "type": "string" }, "images[]": { "description": "The list of files", "type": "array", "items": { "type": "file", "format": "binary" } } } } } } }, "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "type": "object" } } } } } } } } }screenshots (live local server response):


ffroliva commentedon May 27, 2020
What version of
org.springdocshould I need to update to?I am currently working with version 1.3.4.
Regards,
FO
hkosova commentedon May 28, 2020
@tim-lai OAS3 does not have
type: file, it usestype: string+format: binary. Use this definition instead:The

images[]array is displayed as text inputs instead of file inputs:Mahalaxmi-13 commentedon May 28, 2020
@tim-lai What is the maven dependency you use for SwaggerClient release (v3.25.4)
webron commentedon May 28, 2020
@Mahalaxmi-13 We don't supply any maven dependencies that wrap our javascript projects.
ffroliva commentedon May 29, 2020
@webron
this dependency should solve my problem:
JustMik commentedon May 29, 2020
@hkosova @tim-lai I've fixed upload array file items for type string format binary in this PR #6040
tim-lai commentedon Jun 2, 2020
@hkosova closing issue, per resolution with PR #6040. I also fixed the SwaggerClient sample definition.
KuldeepPCodes commentedon Jan 18, 2021
hi, i am facing the same problem in flask_swager_ui , I can not upload array of files files from swagger , when doing request.files i am getting an empty dictionary but i m sending the data from Swagger-UI .