问题
I am using flasgger 0.9.3 with Flask 1.0.2
I am trying to implement the following swagger code on the POST endpoint, so that user can visit the API url/apidocs website and select the endpoint, and then try out the POST request by uploading a document. When I use the below swagger, and put a debugger on request.data
inside the endpoint's python code, it shows request.data
is empty. The foll. is the curl request shown in the browser:
curl -X POST "http://localhost:8081/extract-code" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "file=@finance-block-record-jan2019.xml;type=text/xml"
How can I fix the flasgger code?
@app.route('/extract-code', methods=['POST'])
def extract_code():
"""This is the extract code endpoint.
---
operationId: extract_code
consumes:
- multipart/form-data
produces:
- application/json
parameters:
- in: formData
name: file
required: false
type: file
description: Upload your file.
responses:
200:
description: list of codes
examples:
{"Codes": ["a123x", "xd2221m"]}
"""
来源:https://stackoverflow.com/questions/59559839/how-to-implement-flasgger-code-for-file-upload-request-data-is-empty