marshmallow-code / marshmallow-code/flask-smorest

Swagger UI not allowing upload of text files.

Open
#528 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
717
Forks
77
Avg merge
7h 49m
Merged PRs (30d)
3

Description

Hello!

I was trying to upload two **.txt** files to do some text processing. I uploaded through the input fields in Swagger UI generated by API. But, the Swagger-UI gives me the following error:
Details

![image](https://github.com/marshmallow-code/flask-smorest/assets/84369954/78f10c22-aa29-4fe8-b16a-b545fe7f3c1e)


Here's the relevant parts of the code:
```python
class HeaderSchema(ma.Schema):
id = ma.fields.String()

class MultiFileSchema(ma.Schema):
prev_file = Upload(format='binary')
post_file = Upload(format='binary')

class FormSchema(ma.Schema):
type = ma.fields.String()

@blp.route("/result-file")
class ResultFile(MethodView):
@blp.arguments(HeaderSchema, location='headers')
@blp.arguments(MultiFileSchema, location='files')
@blp.arguments(FormSchema, location='form')
@blp.response(200)
def post(self, header_args = None, files_data = None, form_data = None ):
.
.
.
```
The code works fine when tested using Postman. Problem only shows up in Swagger-UI

Also, when I didn't attach the files in the Swagger-ui, the code worked fine and returned intended response, so **likely the issue might be with the Upload() field.**

What could I be doing wrong?

Thanks!

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the /result-file endpoint in Swagger UI with two .txt uploads, then compare the generated request with the working Postman request. Inspect the generated OpenAPI form schema and Upload fields; done means text files can be selected and submitted successfully through Swagger UI while the existing endpoint behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, openapi, python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.