1

我目前正在使用招摇操作进行多个文件上传。以下是我正在使用的代码:

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"

虽然我在代码中插入了"allowMultiple":True,但它没有显示在招摇的 UI 中。服务器启动后,我尝试查看 html 源代码,“多个”不会显示在表单中。

以下是服务器启动时 swagger ui 的源代码:

<input class="parameter" type="file" name="file[]">

中缺少“多个”一词。

如果我编辑源代码并添加如下“多个”一词,我可以选择多个文件。

<input class="parameter" type="file" name="file[]" multiple>

在这种情况下,似乎"allowMultiple":True对我不起作用。

对我有什么想法或建议吗?

谢谢你。

4

2 回答 2

3

Swagger 不支持这一点。请参阅https://github.com/swagger-api/swagger-spec/issues/254

于 2015-08-03T21:48:07.307 回答
2

这已经被 OpenAPI 3.0 中的 swagger 支持。请参阅https://swagger.io/docs/specification/describing-request-body/file-upload/

例子:

  /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"

效果图

于 2021-06-16T02:35:11.240 回答