mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added validation method for uploaded file using imghdr library
This commit is contained in:
parent
af70dd5dfe
commit
f386039d5a
@ -1,6 +1,7 @@
|
||||
"""
|
||||
JSON serializers for Part app
|
||||
"""
|
||||
import imghdr
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
@ -95,6 +96,15 @@ class PartThumbSerializer(serializers.Serializer):
|
||||
class PartThumbSerializerUpdate(InvenTreeModelSerializer):
|
||||
""" Serializer for updating Part thumbnail """
|
||||
|
||||
def validate_image(self, value):
|
||||
"""
|
||||
Check that file is an image.
|
||||
"""
|
||||
validate = imghdr.what(value)
|
||||
if not validate:
|
||||
raise serializers.ValidationError("File is not an image")
|
||||
return value
|
||||
|
||||
image = InvenTreeAttachmentSerializerField(required=True)
|
||||
|
||||
class Meta:
|
||||
|
Loading…
Reference in New Issue
Block a user