Skip to main content
Version: 0.X.X

FileType

filetype a Python package to infer file type and MIME type checking the magic numbers signature of a file or buffer. we also support the filetype library, and you can import it to your project as follows:

from file_validator.validators import file_validator_by_filetype

Just call this function and give the function path of the file and the mimes you want the files to be validated based on:

from file_validator.validators import file_validator_by_filetype

file_validator_by_filetype(acceptable_mimes=['audio/mpeg', 'video/mp4'], file_path='/path/to/file')
info

Description of the return value and the function parameters:

ParametersTypeDescription
file_pathstringThe path to the file you want to validate
acceptable_mimeslistThe mime of the files you want to validate based on them, example: image/png
Returns:
If everything is OK it will return information about file such file name, file mime,file type, file extensions , otherwise it will return a FileValidationException.
note

To see what types the filetype library supports, you can refer to the link below