marshmallow-code / marshmallow-code/flask-smorest

Multipart requests

Open
#46 38 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
717
Forks
77
Avg merge
7h 49m
Merged PRs (30d)
3

Description

Hello!

I did not found standard way to describe a multipart request. Is it supported?

Currently i had to write something like this to let uploaded files work:

```
request_body_description = {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {"logo": {"type": "string", "format": "binary"}},
}
}
}
}

@bp.route("/update-logo")
class UpdateLogo(MethodView):
@bp.response(code=204)
@bp.doc(requestBody=request_body_description)
def post(self):
file = flask.request.files["logo"]
filename = secure_filename(file.filename)
binary = file.read()

... do something with file ...
```

This code allows swagger to render input type="file" with name "logo" and send multipart request when executing request from web interface.

Am i missing something?

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how @bp.doc handles requestBody descriptions and how the shown flask.request.files usage is represented in the generated OpenAPI document. Compare existing request-body handling and determine what standard multipart support should look like. Done means callers no longer need the manual description and Swagger renders and sends the file input correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, openapi, python
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.