Answer the question
In order to leave comments, you need to log in
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()
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
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 questionAsk a Question
731 491 924 answers to any question