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.
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"
effect picture
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With