Multipart requests
See original GitHub issueHello!
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!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:28 (12 by maintainers)
Top Results From Across the Web
What is http multipart request? - Stack Overflow
An HTTP multipart request is an HTTP request that HTTP clients construct to send files and data over to an HTTP Server.
Read more >A Brief Tour of Multipart Requests - PSPDFKit
The most common use for multipart requests is web forms. When you have a form with only text-based input elements — like text...
Read more >Multipart Request Handling in Spring - Baeldung
Multipart requests consist of sending data of many different types separated by a boundary as part of a single HTTP method call. Generally,...
Read more >Multipart requests - Nine Nines
Multipart requests. Multipart originates from MIME, an Internet standard that extends the format of emails. A multipart message is a list of parts....
Read more >Streaming Multipart Requests - Khanlou
What is a multipart request? Multipart encoding is the de facto way of sending large files over the internet. When you select a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve been banging my head against this a little more. Unfortunately, auto-documenting mixed multipart request bodies is a bit complicated.
There are issues because for instance
arguments
allows to pass description, but this is a requestBody level attribute, not a part (as in multi-part) level attribute, therefore, what we expect from the following would be undetermined:This implementation issues make me think that the sanest way to do that would be to require more explicitness from the user.
We could add a
multipart_arguments
decorator so that we don’t have to detect multipart cases and we can ask for all needed parameters.Things would go relatively smooth if we could pass apispec a schema that would be the aggregation of the different schemas involved ( a single schema inheriting from all). This could avoid duplicating apispec code, or having to pull functions from there to do the job here.
To be able to do so, we’d need to add a restriction to
multipart_argument
: only pass schema classes (or perhaps field dicts), not schema instances. Otherwise, modifiers would be lost in the process. I think we can live with this limitation.I don’t think I’ll do that for the next release.
Once https://github.com/marshmallow-code/flask-smorest/tree/document_multipart_files is merged (almost done, just waiting for apispec 3.0), we’ll be able to send files (using multipart), and to properly set a content type. This is already an improvement.
We shall add a note in the docs saying mixed multipart is not supported.
Any progress here? i am currently looking for a way how to work with this.