1
1
109k42021-01-18 14:02:16
Django
109k4, 2021-01-18 14:02:16

How to fix uploaded files type validation error?

I'm using the django-upload-validator library: https://pypi.org/project/django-upload-validator/ to validate images uploaded by the user, but none of the files pass the validation, including valid images.

views.py

if request.method == "POST":

        userObj = User.objects.get(username=user)
        userData = UserData.objects.get(user=userObj)

        if request.FILES:
            validator = FileTypeValidator(
                allowed_types=['image/png', 'image/jpeg', 'image/svg+xml'],
                allowed_extensions=['.jpeg', '.png', '.svg']
            )

            file_resource = request.FILES['photo']
            validator(file_resource)

            userData.profile_img = request.FILES['photo']
            userData.save()


Mistake

raise MagicException(err)
magic.magic.MagicException: b'could not find any valid magic files!'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2021-01-18
@109k4

Something does not match for you, there is no jp2 in the extensions, but in the image / jpeg types.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question