How to implement flasgger code for file upload? - request.data is empty

你离开我真会死。 提交于 2020-01-16 08:43:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!