marshmallow-code / marshmallow-code/marshmallow

Validating file uploads in Flask Marshmallow

Open
#1,830 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
7.2k
Forks
738
Avg merge
1d 23h
Merged PRs (30d)
7

Description

This is not an issue, this is more of a question, I am sorry if I was not supposed to post it here but I couldn't find anything related to file uploading in the flask-marshmallow (or marshmallow) docs.

- Is there a way to validate file uploads in Flask Marshmallow?

Like uploading images and validate the mime type (if it's png, jpg, gif).

I saw people trying to use validators with no success:

```python
class UploadSchema(Schema):
image = fields.Raw(type="file", validate=FileExtensionValidation())
```

```python
class FileExtensionValidation(Validator)
def __call__(self, value, **kwargs):
....
```

But that lead to nowhere as I am not sure how to read the file submitted to check its name (cant do it from `value` in the example above).

Thanks in advance.

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 reviewing the documented behavior of fields.Raw and the validator pattern shown in the issue, then inspect the Flask-Marshmallow and Marshmallow documentation entry points for file-upload handling. Done would be a clear documented answer about whether uploaded files can be validated this way, including the supported validation boundary or a stated limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.