diff --git a/backend/utils/FileValidator.py b/backend/utils/FileValidator.py index 173e41f84..7b715a22e 100644 --- a/backend/utils/FileValidator.py +++ b/backend/utils/FileValidator.py @@ -8,6 +8,7 @@ from django.template.defaultfilters import filesizeformat from django.utils.translation import gettext_lazy as _ from typing_extensions import NotRequired, Unpack +from unstract.sdk.file_storage.constants import FileOperationParams class FileValidationParam(TypedDict): @@ -69,7 +70,10 @@ def _check_file_extension(self, file: InMemoryUploadedFile) -> None: raise ValidationError(message) def _check_file_mime_type(self, file: InMemoryUploadedFile) -> None: - mimetype = magic.from_buffer(file.read(2048), mime=True) + # TODO: Need to optimise, istead of reading entire file. + mimetype = magic.from_buffer( + file.read(FileOperationParams.READ_ENTIRE_LENGTH), mime=True + ) file.seek(0) # Reset the file pointer to the start if self.allowed_mimetypes and mimetype not in self.allowed_mimetypes: