Handling multi-part requests with files in APIFlask

14 Views Asked by At

The requests library documentation contains instructions on how to POST a multipart encoded file. This allows one to have a POST request with both a json and files part. An example is provided in this Stack Overflow answer.

Is there a way to validate/process this sort of request using APIFlask?

Initially, I imagined this sort of approach might work:

@v1.post("/data")
@v1.input(dataSchema, location="json")  # `dataSchema` describes the JSON part of the request
@v1.input({'file': File()}, location="files") # inline schema dict
def post_data(json_data, file_data):
    ...

However it's specifically stated in the APIFlask documentation that:

you can only declare one body location for your view function, one of: json, form, files, form_and_files, json_or_form.

If I understand things correctly, a single location also implies a single unified schema, whereas I would prefer to keep the JSON schema separate. Can this be achieved in APIFlask?

0

There are 0 best solutions below