Reputation: 91
I am currently doing multiple files upload using swagger operation. Following are the codes that I am working with:
class uploadImage(Resource):
@swagger.operation(
notes='Upload an image file',
parameters=[
{
"name": "file[]",
"description": "Upload an image file. File size limit is 3MB. Only '.jpg' is allowed ",
"required": True,
"allowMultiple": True,
"dataType": 'file',
"paramType": "form"
}
])
def post(self):
files=request.files.getlist['file[]']
filenames = []
for file in files:
filename = secure_filename(file.filename)
filenames.append(filename)
print "Files are uploaded successfully"
Although I inserted "allowMultiple":True in the code, but it did not show in the swagger UI. Once the server is up, I try to view the html source code, "multiple" does not display in the form.
Following is the source code for swagger ui when the server is up:
<input class="parameter" type="file" name="file[]">
The word "multiple" is missing from the .
If I edit the source code and add in the word "multiple" as below, I manage to select multiple files.
<input class="parameter" type="file" name="file[]" multiple>
It seems like "allowMultiple":True does not work for me in this case.
Any idea or suggestion for me?
Thank you.
Upvotes: 3
Views: 23181
Reputation: 131
this already support by swagger in OpenAPI 3.0. See https://swagger.io/docs/specification/describing-request-body/file-upload/
example:
/schema:
get:
tags:
- Schema
description: download schema file
responses:
"200":
description: success
content:
multipart/form-data:
schema:
type: object
properties:
filename:
type: array
items:
type: string
format: binary
"400":
$ref: "#/components/responses/failed"
"404":
$ref: "#/components/responses/notExist"
Upvotes: 7
Reputation: 14830
That's just not supported by Swagger. See https://github.com/swagger-api/swagger-spec/issues/254.
Upvotes: 4