-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsearch-doc.json
More file actions
1 lines (1 loc) · 64.4 KB
/
search-doc.json
File metadata and controls
1 lines (1 loc) · 64.4 KB
1
[{"title":"⚙️ Config","type":0,"sectionRef":"#","url":"/docs/0.X.X/config","content":"⚙️ Config In Windows, you can set the path of the magic.mgc file by adjusting the environmental variable Path_magic_file example: .env path_magic_file='path/to/magic.mgc' ","keywords":""},{"title":"👤 Credits","type":0,"sectionRef":"#","url":"/docs/0.X.X/Credits","content":"","keywords":""},{"title":"Contributors","type":1,"pageTitle":"👤 Credits","url":"/docs/0.X.X/Credits#contributors","content":"None yet. Why not be the first? "},{"title":"💙 Contributing","type":0,"sectionRef":"#","url":"/docs/0.X.X/Contributing","content":"","keywords":""},{"title":"Report Bugs","type":1,"pageTitle":"💙 Contributing","url":"/docs/0.X.X/Contributing#report-bugs","content":"Report bugs at https://github.com/file-validator/file-validator/issues If you are reporting a bug, please include: Your operating system name and version.Any details about your local setup that might be helpful in troubleshooting.Detailed steps to reproduce the bug. "},{"title":"Fix Bugs","type":1,"pageTitle":"💙 Contributing","url":"/docs/0.X.X/Contributing#fix-bugs","content":"Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it. "},{"title":"Implement Features","type":1,"pageTitle":"💙 Contributing","url":"/docs/0.X.X/Contributing#implement-features","content":"Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it. "},{"title":"Write Documentation","type":1,"pageTitle":"💙 Contributing","url":"/docs/0.X.X/Contributing#write-documentation","content":"File Validator could always use more documentation, whether as part of the official File Validator docs, in docstrings, or even on the web in blog posts, articles, and such. "},{"title":"Submit Feedback","type":1,"pageTitle":"💙 Contributing","url":"/docs/0.X.X/Contributing#submit-feedback","content":"The best way to send feedback is to file an issue at https://github.com/file-validator/file-validator/issues If you are proposing a feature: Explain in detail how it would work.Keep the scope as narrow as possible, to make it easier to implement.Remember that this is a volunteer-driven project, and that contributions are welcome :) "},{"title":"Pull Request Guidelines","type":1,"pageTitle":"💙 Contributing","url":"/docs/0.X.X/Contributing#pull-request-guidelines","content":"Before you submit a pull request, check that it meets these guidelines: The pull request should include tests.If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.The pull request should work for Python 3.8, 3.9 and 3.10, and for PyPy.Run the tests before the Pull Request and must be successfully executed and accepted until the Pull Request, and this proves that there is no problem for the codes that are already running.Check your code with Pylint to meet the standards, Pylint analyses your code without actually running it. It checks for errors, enforces a coding standard, looks for code smells, and can make suggestions about how the code could be refactored.You can also use Black to format your codealso check code with pre-commit before release "},{"title":"Config","type":0,"sectionRef":"#","url":"/docs/0.X.X/django/config","content":"Config You should add the following FILE_UPLOAD_HANDLERS settings to your django project settings.py: settings.py FILE_UPLOAD_HANDLERS = [ 'django.core.files.uploadhandler.TemporaryFileUploadHandler', ] add the app to INSTALLED_APPS : settings.py INSTALLED_APPS = [ 'file_validator', ] ","keywords":""},{"title":"Customizing Errors","type":0,"sectionRef":"#","url":"/docs/0.X.X/django/customizing_errors","content":"Customizing Errors It is possible that you can customize the error messages, that is, show the format of the files or mimes in the error message, you can do this in the following way: First, in your Django settings settings.py, you must specify the error message as follows: FILE_VALIDATOR_ERROR_MESSAGE = "{file_name} is not valid" To display the current file name in the error message, you must put the {file} string in your error message for example : 👇 FILE_VALIDATOR_ERROR_MESSAGE = "{file_name} Your custom error message" To display the mimes based on which the file is to be validated, you must include {mimes} string in your error message. for example : 👇 FILE_VALIDATOR_ERROR_MESSAGE = "{mimes} Your custom error message" To display both memes and file name, you can put both in your error message. for example : 👇 FILE_VALIDATOR_ERROR_MESSAGE = "{file_name} and {mimes} Your custom error message" info In this section we will explain the parameters you can use in your message message Parameters\tDescription{file_name}\treturn the current file name {mimes}\treturn the accepted mime {max_file_size}\treturn the Maximum file size that the user can upload {file_size}\treturn the current file size {current_file_mime}\treturn the current file mime","keywords":""},{"title":"Validated File Field","type":0,"sectionRef":"#","url":"/docs/0.X.X/django/forms/validated_file_field","content":"","keywords":""},{"title":"Parameters","type":1,"pageTitle":"Validated File Field","url":"/docs/0.X.X/django/forms/validated_file_field#parameters","content":"info Parameters\tType\tDescriptionaccept\tstr\tThe accept attribute takes as its value a comma-separated list of one or more file types, or unique file type specifiers, describing which file types to allow. See this guide for more familiarity custom_css_class\tstr\tA custom class to customize input multiple\tboolean\tIf you want to upload multiple files, set up to True "},{"title":"How Use ValidatedFilefield?","type":1,"pageTitle":"Validated File Field","url":"/docs/0.X.X/django/forms/validated_file_field#how-use-validatedfilefield","content":"To use ValidatedFilefield you must act as follows: 1.First, import the ValidatedFilefield to your Django forms as follows: from django import forms from file_validator.forms import ValidatedFileField In the next step we have to give it to our form as follows: from django import forms from file_validator.forms import ValidatedFileField class TestForm(forms.Form): test_file = ValidatedFileField( accept='image/*', # => accept attribute custom_css_class='your-custom-css-class', # => custom css class multiple=True # => for upload Multiple Files ) "},{"title":"File Size Validator","type":0,"sectionRef":"#","url":"/docs/0.X.X/django/models/file_size_validator","content":"","keywords":""},{"title":"Parameters","type":1,"pageTitle":"File Size Validator","url":"/docs/0.X.X/django/models/file_size_validator#parameters","content":"info Parameters\tType\tDescriptionmax_upload_file_size\tint\tIf you want the file size to be checked, the file size must be in bytes, example: max_upload_file_size=1048576 (1MB) "},{"title":"Returns","type":1,"pageTitle":"File Size Validator","url":"/docs/0.X.X/django/models/file_size_validator#returns","content":"info Returns:If everything is OK, it will return None, otherwise it will return a ValidationError. "},{"title":"Size conversion table","type":1,"pageTitle":"File Size Validator","url":"/docs/0.X.X/django/models/file_size_validator#size-conversion-table","content":"note To choose the size you want the files to be validated based on, you can take help from the table below or enter your desired size in bytes: Size\tBytes 1 MB\t1048576 B - 10242 B - 220 B 2.5 MB\t2621440 B 5 MB\t5242880 B 10 MB\t10485760 B 20 MB\t20971520 B 50 MB\t52428800 B 100 MB\t104857600 B 250 MB\t262144000 B 500 MB\t524288000 B 1 GB\t1073741824 B 2 GB\t2147483648 B "},{"title":"File Validator","type":0,"sectionRef":"#","url":"/docs/0.X.X/django/models/file_validator","content":"","keywords":""},{"title":"Parameters","type":1,"pageTitle":"File Validator","url":"/docs/0.X.X/django/models/file_validator#parameters","content":"info Parameters\tType\tDescriptionlibraries\tlist optional\tThe value of libraries should be a list of libraries with which you want to perform the validation operation. Example : libraries=["filetype","python_magic", "filetype"] defaults If you do not select any library, it will perform the validation operation with django by default, Supported libraries for validation operations: python_magic, pure_magic, filetype, mimetypes, all, default If you use all, validation operations will be performed with all libraries and if you use default, validation operations will only be done with Django acceptable_mimes\tlist\tThe mimes you want the file to be checked based on. example: acceptable_mimes=['audio/mpeg', 'video/mp4'] max_upload_file_size\tint optional\tIf you want the file size to be checked, the file size must be in bytes, example: max_upload_file_size=1048576 (1MB) defaults to None "},{"title":"Returns","type":1,"pageTitle":"File Validator","url":"/docs/0.X.X/django/models/file_validator#returns","content":"info Returns:If the mime list is empty, raised a value error If the library you entered is not supported, raised a value error, Supported library: filetype, mimetypes, pure_magic, python_magic, all, default if file not valid raises ValidationError "},{"title":"Size conversion table","type":1,"pageTitle":"File Validator","url":"/docs/0.X.X/django/models/file_validator#size-conversion-table","content":"note To choose the size you want the files to be validated based on, you can take help from the table below or enter your desired size in bytes: Size\tBytes 1 MB\t1048576 B - 10242 B - 220 B 2.5 MB\t2621440 B 5 MB\t5242880 B 10 MB\t10485760 B 20 MB\t20971520 B 50 MB\t52428800 B 100 MB\t104857600 B 250 MB\t262144000 B 500 MB\t524288000 B 1 GB\t1073741824 B 2 GB\t2147483648 B "},{"title":"How Use FileValidator?","type":1,"pageTitle":"File Validator","url":"/docs/0.X.X/django/models/file_validator#how-use-filevalidator","content":"To use FileValidator you must act as follows: 1.First, import the FileValidator to your Django model as follows: from django.db import models from file_validator.models import FileValidator In the next step we have to give it to our model as follows: from django.db import models from file_validator.models import FileValidator class TestFileModel(models.Model): test_file = models.FileField( validators=[ FileValidator( libraries=["all"], # => validation operations will be performed with all libraries acceptable_mimes=['audio/mpeg', 'video/mp4'], # => The mimes you want the file to be checked based on. max_upload_file_size=10485760 # => 10 MB ) ] ) Finally run with the following commands: python manage.py makemigrations python manage.py migrate Done ✅ From now on, get the files safely from users. "},{"title":"How Use FileSizeValidator?","type":1,"pageTitle":"File Size Validator","url":"/docs/0.X.X/django/models/file_size_validator#how-use-filesizevalidator","content":"To use FileSizeValidator you must act as follows: 1.First, import the FileSizeValidator to your Django model as follows: from django.db import models from file_validator.models import FileSizeValidator In the next step we have to give it to our model as follows: from django.db import models from file_validator.models import FileSizeValidator class TestFileModel(models.Model): test_file = models.FileField( validators=[ FileSizeValidator( max_upload_file_size=10485760 # => 10 MB ) ] ) Finally run with the following commands: python manage.py makemigrations python manage.py migrate Done ✅ From now on, get the files safely from users. "},{"title":"Validated File Field","type":0,"sectionRef":"#","url":"/docs/0.X.X/django/models/validated_file_field","content":"","keywords":""},{"title":"Parameters","type":1,"pageTitle":"Validated File Field","url":"/docs/0.X.X/django/models/validated_file_field#parameters","content":"info Parameters\tType\tDescriptionlibraries\tlist optional\tThe value of libraries should be a list of libraries with which you want to perform the validation operation. Example : libraries=["filetype","python_magic", "filetype"] defaults If you do not select any library, it will perform the validation operation with django by default, Supported libraries for validation operations: python_magic, pure_magic, filetype, mimetypes, all, default If you use all, validation operations will be performed with all libraries and if you use default, validation operations will only be done with Django acceptable_mimes\tlist\tThe mimes you want the file to be checked based on. example: acceptable_mimes=['audio/mpeg', 'video/mp4'] max_upload_file_size\tint optional\tIf you want the file size to be checked, the file size must be in bytes, example: max_upload_file_size=1048576 (1MB) defaults to None "},{"title":"Returns","type":1,"pageTitle":"Validated File Field","url":"/docs/0.X.X/django/models/validated_file_field#returns","content":"info Returns:If the mime list is empty, raised a value error If the library you entered is not supported, raised a value error, Supported library: filetype, mimetypes, pure_magic, python_magic, all, default if file not valid raises ValidationError "},{"title":"Size conversion table","type":1,"pageTitle":"Validated File Field","url":"/docs/0.X.X/django/models/validated_file_field#size-conversion-table","content":"note To choose the size you want the files to be validated based on, you can take help from the table below or enter your desired size in bytes: Size\tBytes 1 MB\t1048576 B - 10242 B - 220 B 2.5 MB\t2621440 B 5 MB\t5242880 B 10 MB\t10485760 B 20 MB\t20971520 B 50 MB\t52428800 B 100 MB\t104857600 B 250 MB\t262144000 B 500 MB\t524288000 B 1 GB\t1073741824 B 2 GB\t2147483648 B "},{"title":"How Use ValidatedFilefield?","type":1,"pageTitle":"Validated File Field","url":"/docs/0.X.X/django/models/validated_file_field#how-use-validatedfilefield","content":"To use ValidatedFilefield you must act as follows: 1.First, import the ValidatedFilefield to your Django model as follows: from django.db import models from file_validator.models import ValidatedFileField In the next step we have to give it to our model as follows: from django.db import models from file_validator.models import ValidatedFileField class TestFileModel(models.Model): test_file = ValidatedFileField( libraries=["all"], # => validation operations will be performed with all libraries acceptable_mimes=['audio/mpeg', 'video/mp4'], # => The mimes you want the file to be checked based on. max_upload_file_size=10485760 # => 10 MB ) Finally run with the following commands: python manage.py makemigrations python manage.py migrate Done ✅ From now on, get the files safely from users. "},{"title":"📄 History","type":0,"sectionRef":"#","url":"/docs/0.X.X/history","content":"","keywords":""},{"title":"0.0.1 (2022-08-04)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#001-2022-08-04","content":"First release on PyPI. "},{"title":"0.0.2 (2022-08-06)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#002-2022-08-06","content":"Added django file validator "},{"title":"0.0.3 (2022-08-07)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#003-2022-08-07","content":"Added File Validator With File Type LibraryAdded File Validator With Python Magic Library "},{"title":"0.0.4 (2022-08-07)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#004-2022-08-07","content":"Added File Validator "},{"title":"0.0.5 (2022-08-08)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#005-2022-08-08","content":"Added validator for pure python projectAdded get_mime_type_with_python_magic functionAdded get_extension_with_filetype_lib functionAdded get_mime_type_with_filetype_lib functionAdded file_validator_with_filetype_lib function "},{"title":"0.0.6 (2022-08-10)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#006-2022-08-10","content":"Refactoring project files "},{"title":"0.0.7 (2022-08-10)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#007-2022-08-10","content":"Adding Test To Project (file validator for pure python)Deleting get_mime_type_with_python_magicDeleting get_extension_with_filetype_libDeleting get_mime_type_with_filetype_lib "},{"title":"0.0.8 (2022-08-11)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#008-2022-08-11","content":"Adding error message function for customization error messagesAdding constants.py "},{"title":"0.0.9 (2022-08-11)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#009-2022-08-11","content":"Refactoring error message function "},{"title":"0.1.0 (2022-08-12)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#010-2022-08-12","content":"Fixing Minor Bug "},{"title":"0.1.1 (2022-08-12)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#011-2022-08-12","content":"Fixing python magic installation problem "},{"title":"0.1.2 (2022-08-14)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#012-2022-08-14","content":"Fixing installation problem "},{"title":"0.1.3 (2022-08-14)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#013-2022-08-14","content":"Adding installation guide for lib magic "},{"title":"0.1.4 (2022-08-15)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#014-2022-08-15","content":"Refactoring importsRefactoring error messageAdding eq to classRefactoring docstringError handling when the mime type not foundAdding the exception moduleAdding constant error messageRefactor error_message functionFix get the extension problem with the mimetypes library "},{"title":"0.1.5 (2022-08-18)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#015-2022-08-18","content":"Adding File Size ValidationAdding File Validation using Pure Magic LibraryFix Minor Problem "},{"title":"0.1.6 (2022-08-23)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#016-2022-08-23","content":"In this version of file validator, instead of considering a separate class for each library that we want to use for file validation, we considered a whole class and left it to the administrator to choose the library that is going to perform the validation operation. From one class, you can perform validation operations by one or more librariesAdding ConstantsFix AttributeError When Mime Not FoundFix Value Error When Selected One MimeFix Minor Problem "},{"title":"0.1.7 (2023-02-05)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#017-2023-02-05","content":"add ValidatedFileField (django)reach test 100%add size validatoradd file validator by djangorefactoring validatorsImproved code and performanceadd new documentation "},{"title":"0.1.8 (2023-02-05)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#018-2023-02-05","content":"improve and refactoring code "},{"title":"0.1.9 (2023-02-07)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#019-2023-02-07","content":"add file size validator (django)refactor and improve code "},{"title":"0.2.0 (2023-02-08)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#020-2023-02-08","content":"Fix Bug error message function "},{"title":"0.2.1 (2023-02-08)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#021-2023-02-08","content":"Fix Bug ValidatedFileField "},{"title":"0.2.2 (2023-02-09)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#022-2023-02-09","content":"Error Handling when size is not valid in size_validator in ValidatedFileField (#reference) "},{"title":"0.2.3 (2023-02-14)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#023-2023-02-14","content":"add validation in forms level (by Using ValidatedFilefield can you say which type of files are allowed) "},{"title":"0.2.4 (2023-02-15)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#024-2023-02-15","content":"providing custom css class for ValidatedFilefield "},{"title":"0.2.5 (2023-02-16)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#025-2023-02-16","content":"add return statements to file_validator_by_python_magic and providing information about the file "},{"title":"0.2.6 (2023-02-18)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#026-2023-02-18","content":"refactoring validators and now validators return validation data such file_mime, file_extension, file_name etc… "},{"title":"0.2.7 (2023-02-20)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#027-2023-02-20","content":"added file_validator_by_type : file validator for validation of the overall type of files such image, audio, video, archive, fontadded guess_the_type : This function is used to guess the overall type of file such image, audio, video, font and archive "},{"title":"0.2.8 (2023-02-23)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#028-2023-02-23","content":"refactored error message functionadded current file mime and file name to models error message "},{"title":"0.2.9 (2023-02-24)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#029-2023-02-24","content":"when mimes is empty returned MimesEmptyException instead of ValueError #28added multiple attribute to forms #33 "},{"title":"0.3.0 (2023-02-25)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#030-2023-02-25","content":"added file type such image, audio and video to result of validation "},{"title":"0.3.1, 0.3.2, 0.3.3 (2023-03-02)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#031-032-033-2023-03-02","content":"fixed bug for installation python-magic #71 "},{"title":"0.3.4 (2023-03-03)","type":1,"pageTitle":"📄 History","url":"/docs/0.X.X/history#034-2023-03-03","content":"refactored and improved code #75 "},{"title":"▶️ Introduction","type":0,"sectionRef":"#","url":"/docs/0.X.X/intro","content":"","keywords":""},{"title":"What Is File Validator? ✅","type":1,"pageTitle":"▶️ Introduction","url":"/docs/0.X.X/intro#what-is-file-validator-","content":"It is a Python library for file validation based on MIME, size, type and magic numbers that supports Django. "},{"title":"Why should we use this library? 🧐","type":1,"pageTitle":"▶️ Introduction","url":"/docs/0.X.X/intro#why-should-we-use-this-library-","content":"File validation based on MIME, type, extension, magic numbers and size File validation using the filetype library File validation using the python-magic library File validation using the mimetypes library File validation using the puremagic library File validation simultaneously with all libraries File Size validation Provide ValidatedFilefield and FileValidator for file validation in Django Provided ValidatedFilefield in forms with support accept, multiple and custom css attributes Supporting for all mimes "},{"title":"Where to report if we found a bug? 🪲","type":1,"pageTitle":"▶️ Introduction","url":"/docs/0.X.X/intro#where-to-report-if-we-found-a-bug-","content":"Can report the problem through this link "},{"title":"Where should I ask if I had any questions❓","type":1,"pageTitle":"▶️ Introduction","url":"/docs/0.X.X/intro#where-should-i-ask-if-i-had-any-questions","content":"Can you ask your questions through this link "},{"title":"Contributors","type":1,"pageTitle":"▶️ Introduction","url":"/docs/0.X.X/intro#contributors","content":" "},{"title":"💡 Installation","type":0,"sectionRef":"#","url":"/docs/0.X.X/installation","content":"","keywords":""},{"title":"Install Stable release","type":1,"pageTitle":"💡 Installation","url":"/docs/0.X.X/installation#install-stable-release","content":"In this section we start installing File Validator To install File Validator, run this command in your terminal: pip install file-validator caution After installing file validator, we need to install libmagic, which you need to install using the following command: for windows: pip install python-magic-bin for Debian/Ubuntu: sudo apt-get install libmagic1 for OSX: When using Homebrew: brew install libmagic When using macports: port install file This is the preferred method to install File Validator, as it will always install the most recent stable release If you don’t have pip installed, this Python installation guide can guide you through the process. "},{"title":"From sources","type":1,"pageTitle":"💡 Installation","url":"/docs/0.X.X/installation#from-sources","content":"The sources for File Validator can be downloaded from the Github repo. You can either clone the public repository: git clone git://github.com/file-validator/file-validator Or download the tarball: curl -OJL https://github.com/file-validator/file-validator/tarball/master Once you have a copy of the source, you can install it with: python setup.py install "},{"title":"file validator by type","type":0,"sectionRef":"#","url":"/docs/0.X.X/usage/file_validator_by_type","content":"file validator by type this file validator for validation of the overall type of files such image, audio, video, archive, font from file_validator.validators import file_validator_by_type 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_type file_validator_by_type(acceptable_types=['image'], file_path='/path/to/file') info Description of the return value and the function parameters: Parameters\tType\tDescriptionfile_path\tstring\tThe path to the file you want to validate acceptable_types\tlist\tacceptable types of file, Supported types image, video, audio, archive, fontReturns:If everything is OK it will return information about file such file name, file type , otherwise it will return a FileValidationException. note To see what types the filetype library supports, you can refer to the link below","keywords":""},{"title":"MimeTypes","type":0,"sectionRef":"#","url":"/docs/0.X.X/usage/mimetypes","content":"MimeTypes The good news is that we also support the native Python library, mimetypes MimeTypes, and you can add it to your project as follows: from file_validator.validators import file_validator_by_mimetypes 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_mimetypes file_validator_by_mimetypes(acceptable_mimes=['audio/mpeg', 'video/mp4'], file_path='/path/to/file') info Description of the return value and the function parameters: Parameters\tType\tDescriptionfile_path\tstring\tThe path to the file you want to validate acceptable_mimes\tlist\tThe mime of the files you want to validate based on them, example: image/pngReturns:If everything is OK it will return information about file such file name,file type, file mime, file extensions , otherwise it will return a FileValidationException.","keywords":""},{"title":"FileType","type":0,"sectionRef":"#","url":"/docs/0.X.X/usage/filetype","content":"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: Parameters\tType\tDescriptionfile_path\tstring\tThe path to the file you want to validate acceptable_mimes\tlist\tThe mime of the files you want to validate based on them, example: image/pngReturns: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","keywords":""},{"title":"🏷️ Versions","type":0,"sectionRef":"#","url":"/docs/0.X.X/versions","content":"🏷️ Versions you can access the version 0.X.X (0.0.1 to 0.3.4) documentation in the below link: 0.X.X documentation you can access the version 1.X.X (1.0.0 to ...) documentation in the below link: 1.X.X documentation","keywords":""},{"title":"Pure Magic","type":0,"sectionRef":"#","url":"/docs/0.X.X/usage/pure_magic","content":"Pure Magic puremagic is a pure python module that will identify a file based off it's magic numbers.It is designed to be minimalistic and inherently cross platform compatible. It is also designed to be a stand in for python-magic, it incorporates the functions from_file(filename[, mime]) and from_string(string[, mime]) however the magic_file() and magic_string() are more powerful and will also display confidence and duplicate matches. you can add it to your project as follows: from file_validator.validators import file_validator_by_pure_magic 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_pure_magic file_validator_by_pure_magic(acceptable_mimes=['audio/mpeg', 'video/mp4'], file_path='/path/to/file') info Description of the return value and the function parameters: Parameters\tType\tDescriptionfile_path\tstring\tThe path to the file you want to validate acceptable_mimes\tlist\tThe mime of the files you want to validate based on them, example: image/pngReturns: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.","keywords":""},{"title":"Python Magic","type":0,"sectionRef":"#","url":"/docs/0.X.X/usage/python_magic","content":"Python Magic python-magic is a Python interface to the libmagic file type identification library. libmagic identifies file types by checking their headers according to a predefined list of file types. This functionality is exposed to the command line by the Unix command file. caution Since the python-magiclibrary may treat audio files like mp3 as programs or application/octet-stream and it’s a bit annoying, I suggest when you want to validate audio files from two libraries (filetype, MimeTypes, pure magic) or use the safe mode method. If you want to use File Validators made using the python-magiclibrary, you should add it to your program as follows: from file_validator.validators import file_validator_by_python_magic 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_python_magic file_validator_by_python_magic(acceptable_mimes=['audio/mpeg', 'video/mp4'], file_path='/path/to/file') info Description of the return value and the function parameters: Parameters\tType\tDescriptionfile_path\tstring\tThe path to the file you want to validate acceptable_mimes\tlist\tThe 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.","keywords":""},{"title":"Safe Mode 🔒","type":0,"sectionRef":"#","url":"/docs/0.X.X/usage/safe_mode","content":"Safe Mode 🔒 By using Safe Mode, you can perform validation operations using all libraries at the same time To use, first import as in the example below: from file_validator.validators import file_validator 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 file_validator(acceptable_mimes=['audio/mpeg', 'video/mp4'], file_path='/path/to/file') info Description of the return value and the function parameters: Parameters\tType\tDescriptionfile_path\tstring\tThe path to the file you want to validate acceptable_mimes\tlist\tThe mime of the files you want to validate based on them, example: image/pngReturns:If everything is OK it will return information about file such file name, file mime, file extensions , otherwise it will return a FileValidationException. note To see what types the filetype library supports, you can refer to the link below","keywords":""},{"title":"⚙️ Config","type":0,"sectionRef":"#","url":"/docs/config","content":"⚙️ Config In Windows, you can set the path of the magic.mgc file by adjusting the environmental variable Path_magic_file example: .env path_magic_file='path/to/magic.mgc' ","keywords":""},{"title":"👤 Credits","type":0,"sectionRef":"#","url":"/docs/Credits","content":"","keywords":""},{"title":"Contributors","type":1,"pageTitle":"👤 Credits","url":"/docs/Credits#contributors","content":"None yet. Why not be the first? "},{"title":"💙 Contributing","type":0,"sectionRef":"#","url":"/docs/Contributing","content":"","keywords":""},{"title":"Report Bugs","type":1,"pageTitle":"💙 Contributing","url":"/docs/Contributing#report-bugs","content":"Report bugs at https://github.com/file-validator/file-validator/issues If you are reporting a bug, please include: Your operating system name and version.Any details about your local setup that might be helpful in troubleshooting.Detailed steps to reproduce the bug. "},{"title":"Fix Bugs","type":1,"pageTitle":"💙 Contributing","url":"/docs/Contributing#fix-bugs","content":"Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it. "},{"title":"Implement Features","type":1,"pageTitle":"💙 Contributing","url":"/docs/Contributing#implement-features","content":"Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it. "},{"title":"Write Documentation","type":1,"pageTitle":"💙 Contributing","url":"/docs/Contributing#write-documentation","content":"File Validator could always use more documentation, whether as part of the official File Validator docs, in docstrings, or even on the web in blog posts, articles, and such. "},{"title":"Submit Feedback","type":1,"pageTitle":"💙 Contributing","url":"/docs/Contributing#submit-feedback","content":"The best way to send feedback is to file an issue at https://github.com/file-validator/file-validator/issues If you are proposing a feature: Explain in detail how it would work.Keep the scope as narrow as possible, to make it easier to implement.Remember that this is a volunteer-driven project, and that contributions are welcome :) "},{"title":"Pull Request Guidelines","type":1,"pageTitle":"💙 Contributing","url":"/docs/Contributing#pull-request-guidelines","content":"Before you submit a pull request, check that it meets these guidelines: The pull request should include tests.If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.The pull request should work for Python 3.8, 3.9 and 3.10, and for PyPy.Run the tests before the Pull Request and must be successfully executed and accepted until the Pull Request, and this proves that there is no problem for the codes that are already running.Check your code with Pylint to meet the standards, Pylint analyses your code without actually running it. It checks for errors, enforces a coding standard, looks for code smells, and can make suggestions about how the code could be refactored.You can also use Black to format your codealso check code with pre-commit before release "},{"title":"Customizing Errors","type":0,"sectionRef":"#","url":"/docs/django/customizing_errors","content":"Customizing Errors It is possible that you can customize the error messages, that is, show the format of the files or mimes in the error message, you can do this in the following way: First, in your Django settings settings.py, you must specify the error message as follows: FILE_VALIDATOR_ERROR_MESSAGE = "{current_file_name} is not valid" To display the current file name in the error message, you must put the {current_file_name} string in your error message for example : 👇 FILE_VALIDATOR_ERROR_MESSAGE = "{current_file_name} Your custom error message" To display the mimes based on which the file is to be validated, you must include {acceptable_mimes} string in your error message. for example : 👇 FILE_VALIDATOR_ERROR_MESSAGE = "{acceptable_mimes} Your custom error message" To display both mimes and file name, you can put both in your error message. for example : 👇 FILE_VALIDATOR_ERROR_MESSAGE = "{current_file_name} and {acceptable_mimes} Your custom error message" info In this section we will explain the parameters you can use in your message message Parameters\tDescription{current_file_name}\treturn the current file name {current_file_size}\treturn the current file size {current_file_mime}\treturn the current file mime {current_file_type}\treturn the current file type {current_file_extension}\treturn the current file extension {acceptable_mimes}\treturn the accepted mime {acceptable_types}\treturn the accepted type {acceptable_extensions}\treturn the accepted extension {max_file_size}\treturn the Maximum file size that the user can upload","keywords":""},{"title":"Config","type":0,"sectionRef":"#","url":"/docs/django/config","content":"Config You should add the following FILE_UPLOAD_HANDLERS settings to your django project settings.py: settings.py FILE_UPLOAD_HANDLERS = [ 'django.core.files.uploadhandler.TemporaryFileUploadHandler', ] add the app to INSTALLED_APPS : settings.py INSTALLED_APPS = [ 'file_validator', ] ","keywords":""},{"title":"Validated File Field","type":0,"sectionRef":"#","url":"/docs/django/forms/validated_file_field","content":"","keywords":""},{"title":"Parameters","type":1,"pageTitle":"Validated File Field","url":"/docs/django/forms/validated_file_field#parameters","content":"info Parameters\tType\tDescriptionaccept\tstr\tThe accept attribute takes as its value a comma-separated list of one or more file types, or unique file type specifiers, describing which file types to allow. See this guide for more familiarity custom_css_class\tstr\tA custom class to customize input multiple\tboolean\tIf you want to upload multiple files, set up to True "},{"title":"How Use ValidatedFilefield?","type":1,"pageTitle":"Validated File Field","url":"/docs/django/forms/validated_file_field#how-use-validatedfilefield","content":"To use ValidatedFilefield you must act as follows: 1.First, import the ValidatedFilefield to your Django forms as follows: from django import forms from file_validator.forms import ValidatedFileField In the next step we have to give it to our form as follows: from django import forms from file_validator.forms import ValidatedFileField class TestForm(forms.Form): test_file = ValidatedFileField( accept='image/*', # => accept attribute custom_css_class='your-custom-css-class', # => custom css class multiple=True # => for upload Multiple Files ) "},{"title":"File Size Validator","type":0,"sectionRef":"#","url":"/docs/django/models/file_size_validator","content":"","keywords":""},{"title":"Parameters","type":1,"pageTitle":"File Size Validator","url":"/docs/django/models/file_size_validator#parameters","content":"info Parameters\tType\tDescriptionmax_upload_file_size\tint\tIf you want the file size to be checked, the file size must be in bytes, example: max_upload_file_size=1048576 (1MB) "},{"title":"Returns","type":1,"pageTitle":"File Size Validator","url":"/docs/django/models/file_size_validator#returns","content":"info Returns:If everything is OK, it will return None, otherwise it will return a ValidationError. "},{"title":"Size conversion table","type":1,"pageTitle":"File Size Validator","url":"/docs/django/models/file_size_validator#size-conversion-table","content":"note To choose the size you want the files to be validated based on, you can take help from the table below or enter your desired size in bytes: Size\tBytes 1 MB\t1048576 B - 10242 B - 220 B 2.5 MB\t2621440 B 5 MB\t5242880 B 10 MB\t10485760 B 20 MB\t20971520 B 50 MB\t52428800 B 100 MB\t104857600 B 250 MB\t262144000 B 500 MB\t524288000 B 1 GB\t1073741824 B 2 GB\t2147483648 B "},{"title":"How Use FileSizeValidator?","type":1,"pageTitle":"File Size Validator","url":"/docs/django/models/file_size_validator#how-use-filesizevalidator","content":"To use FileSizeValidator you must act as follows: 1.First, import the FileSizeValidator to your Django model as follows: from django.db import models from file_validator.models import FileSizeValidator In the next step we have to give it to our model as follows: from django.db import models from file_validator.models import FileSizeValidator class TestFileModel(models.Model): test_file = models.FileField( validators=[ FileSizeValidator( max_upload_file_size=10485760 # => 10 MB ) ] ) Finally run with the following commands: python manage.py makemigrations python manage.py migrate Done ✅ From now on, get the files safely from users. "},{"title":"📄 History","type":0,"sectionRef":"#","url":"/docs/history","content":"","keywords":""},{"title":"0.0.1 (2022-08-04)","type":1,"pageTitle":"📄 History","url":"/docs/history#001-2022-08-04","content":"First release on PyPI. "},{"title":"0.0.2 (2022-08-06)","type":1,"pageTitle":"📄 History","url":"/docs/history#002-2022-08-06","content":"Added django file validator "},{"title":"0.0.3 (2022-08-07)","type":1,"pageTitle":"📄 History","url":"/docs/history#003-2022-08-07","content":"Added File Validator With File Type LibraryAdded File Validator With Python Magic Library "},{"title":"0.0.4 (2022-08-07)","type":1,"pageTitle":"📄 History","url":"/docs/history#004-2022-08-07","content":"Added File Validator "},{"title":"0.0.5 (2022-08-08)","type":1,"pageTitle":"📄 History","url":"/docs/history#005-2022-08-08","content":"Added validator for pure python projectAdded get_mime_type_with_python_magic functionAdded get_extension_with_filetype_lib functionAdded get_mime_type_with_filetype_lib functionAdded file_validator_with_filetype_lib function "},{"title":"0.0.6 (2022-08-10)","type":1,"pageTitle":"📄 History","url":"/docs/history#006-2022-08-10","content":"Refactoring project files "},{"title":"0.0.7 (2022-08-10)","type":1,"pageTitle":"📄 History","url":"/docs/history#007-2022-08-10","content":"Adding Test To Project (file validator for pure python)Deleting get_mime_type_with_python_magicDeleting get_extension_with_filetype_libDeleting get_mime_type_with_filetype_lib "},{"title":"0.0.8 (2022-08-11)","type":1,"pageTitle":"📄 History","url":"/docs/history#008-2022-08-11","content":"Adding error message function for customization error messagesAdding constants.py "},{"title":"0.0.9 (2022-08-11)","type":1,"pageTitle":"📄 History","url":"/docs/history#009-2022-08-11","content":"Refactoring error message function "},{"title":"0.1.0 (2022-08-12)","type":1,"pageTitle":"📄 History","url":"/docs/history#010-2022-08-12","content":"Fixing Minor Bug "},{"title":"0.1.1 (2022-08-12)","type":1,"pageTitle":"📄 History","url":"/docs/history#011-2022-08-12","content":"Fixing python magic installation problem "},{"title":"0.1.2 (2022-08-14)","type":1,"pageTitle":"📄 History","url":"/docs/history#012-2022-08-14","content":"Fixing installation problem "},{"title":"0.1.3 (2022-08-14)","type":1,"pageTitle":"📄 History","url":"/docs/history#013-2022-08-14","content":"Adding installation guide for lib magic "},{"title":"0.1.4 (2022-08-15)","type":1,"pageTitle":"📄 History","url":"/docs/history#014-2022-08-15","content":"Refactoring importsRefactoring error messageAdding eq to classRefactoring docstringError handling when the mime type not foundAdding the exception moduleAdding constant error messageRefactor error_message functionFix get the extension problem with the mimetypes library "},{"title":"0.1.5 (2022-08-18)","type":1,"pageTitle":"📄 History","url":"/docs/history#015-2022-08-18","content":"Adding File Size ValidationAdding File Validation using Pure Magic LibraryFix Minor Problem "},{"title":"0.1.6 (2022-08-23)","type":1,"pageTitle":"📄 History","url":"/docs/history#016-2022-08-23","content":"In this version of file validator, instead of considering a separate class for each library that we want to use for file validation, we considered a whole class and left it to the administrator to choose the library that is going to perform the validation operation. From one class, you can perform validation operations by one or more librariesAdding ConstantsFix AttributeError When Mime Not FoundFix Value Error When Selected One MimeFix Minor Problem "},{"title":"0.1.7 (2023-02-05)","type":1,"pageTitle":"📄 History","url":"/docs/history#017-2023-02-05","content":"add ValidatedFileField (django)reach test 100%add size validatoradd file validator by djangorefactoring validatorsImproved code and performanceadd new documentation "},{"title":"0.1.8 (2023-02-05)","type":1,"pageTitle":"📄 History","url":"/docs/history#018-2023-02-05","content":"improve and refactoring code "},{"title":"0.1.9 (2023-02-07)","type":1,"pageTitle":"📄 History","url":"/docs/history#019-2023-02-07","content":"add file size validator (django)refactor and improve code "},{"title":"0.2.0 (2023-02-08)","type":1,"pageTitle":"📄 History","url":"/docs/history#020-2023-02-08","content":"Fix Bug error message function "},{"title":"0.2.1 (2023-02-08)","type":1,"pageTitle":"📄 History","url":"/docs/history#021-2023-02-08","content":"Fix Bug ValidatedFileField "},{"title":"0.2.2 (2023-02-09)","type":1,"pageTitle":"📄 History","url":"/docs/history#022-2023-02-09","content":"Error Handling when size is not valid in size_validator in ValidatedFileField (#reference) "},{"title":"0.2.3 (2023-02-14)","type":1,"pageTitle":"📄 History","url":"/docs/history#023-2023-02-14","content":"add validation in forms level (by Using ValidatedFilefield can you say which type of files are allowed) "},{"title":"0.2.4 (2023-02-15)","type":1,"pageTitle":"📄 History","url":"/docs/history#024-2023-02-15","content":"providing custom css class for ValidatedFilefield "},{"title":"0.2.5 (2023-02-16)","type":1,"pageTitle":"📄 History","url":"/docs/history#025-2023-02-16","content":"add return statements to file_validator_by_python_magic and providing information about the file "},{"title":"0.2.6 (2023-02-18)","type":1,"pageTitle":"📄 History","url":"/docs/history#026-2023-02-18","content":"refactoring validators and now validators return validation data such file_mime, file_extension, file_name etc… "},{"title":"0.2.7 (2023-02-20)","type":1,"pageTitle":"📄 History","url":"/docs/history#027-2023-02-20","content":"added file_validator_by_type : file validator for validation of the overall type of files such image, audio, video, archive, fontadded guess_the_type : This function is used to guess the overall type of file such image, audio, video, font and archive "},{"title":"0.2.8 (2023-02-23)","type":1,"pageTitle":"📄 History","url":"/docs/history#028-2023-02-23","content":"refactored error message functionadded current file mime and file name to models error message "},{"title":"0.2.9 (2023-02-24)","type":1,"pageTitle":"📄 History","url":"/docs/history#029-2023-02-24","content":"when mimes is empty returned MimesEmptyException instead of ValueError #28added multiple attribute to forms #33 "},{"title":"0.3.0 (2023-02-25)","type":1,"pageTitle":"📄 History","url":"/docs/history#030-2023-02-25","content":"added file type such image, audio and video to result of validation "},{"title":"0.3.1, 0.3.2, 0.3.3 (2023-03-02)","type":1,"pageTitle":"📄 History","url":"/docs/history#031-032-033-2023-03-02","content":"fixed bug for installation python-magic #71 "},{"title":"0.3.4 (2023-03-03)","type":1,"pageTitle":"📄 History","url":"/docs/history#034-2023-03-03","content":"refactored and improved code #75 "},{"title":"1.0.0","type":1,"pageTitle":"📄 History","url":"/docs/history#100","content":"In the 0.X.X version, each of the File Validats was a separate function but in this version they are all become a class In the new version you can validate files based on extension, mime and size separately "},{"title":"1.0.1","type":1,"pageTitle":"📄 History","url":"/docs/history#101","content":"fixing to wrong use acceptable_mimes instead of guessed_mimes in #166 "},{"title":"1.0.2","type":1,"pageTitle":"📄 History","url":"/docs/history#102","content":"fix and modified error message for validate extension method in #167 "},{"title":"1.0.3","type":1,"pageTitle":"📄 History","url":"/docs/history#103","content":"fixing error message parameters name in #169 "},{"title":"1.0.4","type":1,"pageTitle":"📄 History","url":"/docs/history#104","content":"fixing problem for getting file size in drf in #170 "},{"title":"1.0.5","type":1,"pageTitle":"📄 History","url":"/docs/history#105","content":"fix 'File' object has no attribute 'content_type' error #191 "},{"title":"1.0.6","type":1,"pageTitle":"📄 History","url":"/docs/history#106","content":"fix Not apply "null=True" and "blank=True" in ValidatedFileField #195 "},{"title":"1.0.7, 1.0.8","type":1,"pageTitle":"📄 History","url":"/docs/history#107-108","content":"added extras_require to setup.py #201 "},{"title":"1.0.9","type":1,"pageTitle":"📄 History","url":"/docs/history#109","content":"fix module not found error no module named django #205 "},{"title":"💡 Installation","type":0,"sectionRef":"#","url":"/docs/installation","content":"","keywords":""},{"title":"Install Stable release","type":1,"pageTitle":"💡 Installation","url":"/docs/installation#install-stable-release","content":"In this section we start installing File Validator To install File Validator, run this command in your terminal: pip install file-validator caution After installing file validator, we need to install libmagic, which you need to install using the following command: for windows: pip install python-magic-bin for Debian/Ubuntu: sudo apt-get install libmagic1 for OSX: When using Homebrew: brew install libmagic When using macports: port install file This is the preferred method to install File Validator, as it will always install the most recent stable release If you don’t have pip installed, this Python installation guide can guide you through the process. "},{"title":"From sources","type":1,"pageTitle":"💡 Installation","url":"/docs/installation#from-sources","content":"The sources for File Validator can be downloaded from the Github repo. You can either clone the public repository: git clone git://github.com/file-validator/file-validator Or download the tarball: curl -OJL https://github.com/file-validator/file-validator/tarball/master Once you have a copy of the source, you can install it with: python setup.py install "},{"title":"Django File Validator","type":0,"sectionRef":"#","url":"/docs/django/models/django_file_validator","content":"","keywords":""},{"title":"Parameters","type":1,"pageTitle":"Django File Validator","url":"/docs/django/models/django_file_validator#parameters","content":"info Parameters\tType\tDescriptionlibraries\tlist optional\tThe value of libraries should be a list of libraries with which you want to perform the validation operation. Example : libraries=["filetype","python_magic", "filetype"] defaults If you do not select any library, it will perform the validation operation with django by default, Supported libraries for validation operations: python_magic, pure_magic, filetype, mimetypes, all, default If you use all, validation operations will be performed with all libraries and if you use default, validation operations will only be done with Django acceptable_mimes\tlist\tThe mimes you want the file to be checked based on. example: acceptable_mimes=['audio/mpeg', 'video/mp4'] acceptable_types\tlist\tThe types you want the file to be checked based on. example: acceptable_types=['audio', 'video'] max_upload_file_size\tint optional\tIf you want the file size to be checked, the file size must be in bytes, example: max_upload_file_size=1048576 (1MB) defaults to None "},{"title":"▶️ Introduction","type":0,"sectionRef":"#","url":"/docs/intro","content":"","keywords":""},{"title":"What Is File Validator? ✅","type":1,"pageTitle":"▶️ Introduction","url":"/docs/intro#what-is-file-validator-","content":"It is a Python library for file validation based on MIME, size, type and magic numbers that supports Django. "},{"title":"Why should we use this library? 🧐","type":1,"pageTitle":"▶️ Introduction","url":"/docs/intro#why-should-we-use-this-library-","content":"File validation based on MIME, type, extension, magic numbers and size File validation using the filetype library File validation using the python-magic library File validation using the mimetypes library File validation using the puremagic library File validation simultaneously with all libraries File Size validation Provide ValidatedFilefield and FileValidator for file validation in Django Provided ValidatedFilefield in forms with support accept, multiple and custom css attributes Supporting for all mimes "},{"title":"Where to report if we found a bug? 🪲","type":1,"pageTitle":"▶️ Introduction","url":"/docs/intro#where-to-report-if-we-found-a-bug-","content":"Can report the problem through this link "},{"title":"Where should I ask if I had any questions❓","type":1,"pageTitle":"▶️ Introduction","url":"/docs/intro#where-should-i-ask-if-i-had-any-questions","content":"Can you ask your questions through this link "},{"title":"Contributors","type":1,"pageTitle":"▶️ Introduction","url":"/docs/intro#contributors","content":" "},{"title":"Returns","type":1,"pageTitle":"Django File Validator","url":"/docs/django/models/django_file_validator#returns","content":"info Returns:If the mime list is empty, raised a value error If the library you entered is not supported, raised a value error, Supported library: filetype, mimetypes, pure_magic, python_magic, all, default if file not valid raises ValidationError At least one of the parameters of acceptable_mimes or acceptable_types must be filled else EmptyParametersException error occurs If the type you enter in acceptable_types is not supported by the file-validator library, it will cause TypeNotSupportedException error, supported types are audio, video, image, font and archive "},{"title":"Size conversion table","type":1,"pageTitle":"Django File Validator","url":"/docs/django/models/django_file_validator#size-conversion-table","content":"note To choose the size you want the files to be validated based on, you can take help from the table below or enter your desired size in bytes: Size\tBytes 1 MB\t1048576 B - 10242 B - 220 B 2.5 MB\t2621440 B 5 MB\t5242880 B 10 MB\t10485760 B 20 MB\t20971520 B 50 MB\t52428800 B 100 MB\t104857600 B 250 MB\t262144000 B 500 MB\t524288000 B 1 GB\t1073741824 B 2 GB\t2147483648 B "},{"title":"How Use DjangoFileValidator?","type":1,"pageTitle":"Django File Validator","url":"/docs/django/models/django_file_validator#how-use-djangofilevalidator","content":"To use FileValidator you must act as follows: 1.First, import the DjangoFileValidator to your Django model as follows: from django.db import models from file_validator.models import DjangoFileValidator In the next step we have to give it to our model as follows: from django.db import models from file_validator.models import DjangoFileValidator class TestFileModel(models.Model): test_file = models.FileField( validators=[ DjangoFileValidator( libraries=["python_magic", "filetype"], # => validation operations will be performed with python-magic and filetype libraries acceptable_mimes=['audio/mpeg', 'video/mp4', 'image/png'], # => The mimes you want the file to be checked based on. acceptable_types=['audio', 'video', 'image'], # => The types you want the file to be checked based on. max_upload_file_size=10485760 # => 10 MB ) ] ) Finally run with the following commands: python manage.py makemigrations python manage.py migrate Done ✅ From now on, get the files safely from users. "},{"title":"Validated File Field","type":0,"sectionRef":"#","url":"/docs/django/models/validated_file_field","content":"","keywords":""},{"title":"🏷️ Versions","type":0,"sectionRef":"#","url":"/docs/versions","content":"🏷️ Versions you can access the version 0.X.X (0.0.1 to 0.3.4) documentation in the below link: 0.X.X documentation you can access the version 1.X.X (1.0.0 to ...) documentation in the below link: 1.X.X documentation","keywords":""},{"title":"Parameters","type":1,"pageTitle":"Validated File Field","url":"/docs/django/models/validated_file_field#parameters","content":"info Parameters\tType\tDescriptionlibraries\tlist optional\tThe value of libraries should be a list of libraries with which you want to perform the validation operation. Example : libraries=["filetype","python_magic", "filetype"] defaults If you do not select any library, it will perform the validation operation with django by default, Supported libraries for validation operations: python_magic, pure_magic, filetype, mimetypes, all, default If you use all, validation operations will be performed with all libraries and if you use default, validation operations will only be done with Django acceptable_mimes\tlist\tThe mimes you want the file to be checked based on. example: acceptable_mimes=['audio/mpeg', 'video/mp4'] acceptable_types\tlist\tThe types you want the file to be checked based on. example: acceptable_types=['audio', 'video'] max_upload_file_size\tint optional\tIf you want the file size to be checked, the file size must be in bytes, example: max_upload_file_size=1048576 (1MB) defaults to None "},{"title":"Returns","type":1,"pageTitle":"Validated File Field","url":"/docs/django/models/validated_file_field#returns","content":"info Returns:If the mime list is empty, raised a value error If the library you entered is not supported, raised a value error, Supported library: filetype, mimetypes, pure_magic, python_magic, all, default if file not valid raises ValidationError At least one of the parameters of acceptable_mimes or acceptable_types must be filled else EmptyParametersException error occurs If the type you enter in acceptable_types is not supported by the file-validator library, it will cause TypeNotSupportedException error, supported types are audio, video, image, font and archive "},{"title":"Size conversion table","type":1,"pageTitle":"Validated File Field","url":"/docs/django/models/validated_file_field#size-conversion-table","content":"note To choose the size you want the files to be validated based on, you can take help from the table below or enter your desired size in bytes: Size\tBytes 1 MB\t1048576 B - 10242 B - 220 B 2.5 MB\t2621440 B 5 MB\t5242880 B 10 MB\t10485760 B 20 MB\t20971520 B 50 MB\t52428800 B 100 MB\t104857600 B 250 MB\t262144000 B 500 MB\t524288000 B 1 GB\t1073741824 B 2 GB\t2147483648 B "},{"title":"How Use ValidatedFilefield?","type":1,"pageTitle":"Validated File Field","url":"/docs/django/models/validated_file_field#how-use-validatedfilefield","content":"To use ValidatedFilefield you must act as follows: 1.First, import the ValidatedFilefield to your Django model as follows: from django.db import models from file_validator.models import ValidatedFileField In the next step we have to give it to our model as follows: from django.db import models from file_validator.models import ValidatedFileField class TestFileModel(models.Model): test_file = ValidatedFileField( libraries=["all"], # => validation operations will be performed with all libraries acceptable_mimes=['audio/mpeg', 'video/mp4'], # => The mimes you want the file to be checked based on. acceptable_types=['audio', 'video'], # => The types you want the file to be checked based on. max_upload_file_size=10485760 # => 10 MB ) Finally run with the following commands: python manage.py makemigrations python manage.py migrate Done ✅ From now on, get the files safely from users. "},{"title":"File Validator","type":0,"sectionRef":"#","url":"/docs/usage/file_validator","content":"","keywords":""},{"title":"How Used?","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#how-used","content":""},{"title":"First Imported","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#first-imported","content":"You must first import FileValidator to use: from file_validator.validators import FileValidator "},{"title":"Create Instance","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#create-instance","content":"At this point you should make an instance from the FileValidator class: file_validator = FileValidator( acceptable_extensions=[".png"], max_upload_file_size=1000000, acceptable_types=["image", "audio"], acceptable_mimes=["image/png"], file_path="path/to/file", ) Parameters explanation info Parameters\tType\tDescriptionmax_upload_file_size\tint optional\tIf you want the file size to be checked, the file size must be in bytes, example: max_upload_file_size=1048576 (1MB) defaults to None acceptable_extensions\tlist optional\tThe extensions you want the file to be checked based on. example: acceptable_extensions=[".png"] acceptable_types\tlist\tThe types you want the file to be checked based on. example: acceptable_types=['audio', 'video'] acceptable_mimes\tlist\tThe mimes you want the file to be checked based on. example: acceptable_mimes=['audio/mpeg', 'video/mp4'] file_path\tstring\tThe file path that you want to be validated "},{"title":"python-magic Library","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#python-magic-library","content":"If you want to perform file validation operations by the python-magic Library, you should use the python_magic() method as follows: file_validator.python_magic() "},{"title":"pure-magic Library","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#pure-magic-library","content":"If you want to perform file validation operations by the pure-magic Library, you should use the pure_magic() method as follows: file_validator.pure_magic() "},{"title":"mimetypes Library","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#mimetypes-library","content":"If you want to perform file validation operations by the mimetypes Library, you should use the mimetypes() method as follows: file_validator.mimetypes() "},{"title":"filetype Library","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#filetype-library","content":"If you want to perform file validation operations by the filetype Library, you should use the filetype() method as follows: file_validator.filetype() "},{"title":"All Library","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#all-library","content":"If you want to perform file validation operations by the All libraries , you should use the validate() method as follows: file_validator.validate() "},{"title":"File Validation Based On The Extension","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#file-validation-based-on-the-extension","content":"If you want to validate the files based on their extension, you should use the validate_extension() method: file_validator.validate_extension() "},{"title":"File Validation Based On The Mime","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#file-validation-based-on-the-mime","content":"If you want to validate the files based on their MIME and their magic numbers, you should use the validate_mime() method: file_validator.validate_mime() "},{"title":"File Validation Based On The type","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#file-validation-based-on-the-type","content":"If you want to validate the files based on their type such image, audio, video and etc..., you should use the validate_type() method: file_validator.validate_type() "},{"title":"File Validation Based On The Size","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#file-validation-based-on-the-size","content":"If you want to validate the files based on their size, you should use the validate_size() method: file_validator.validate_size() "},{"title":"Size conversion table","type":1,"pageTitle":"File Validator","url":"/docs/usage/file_validator#size-conversion-table","content":"note To choose the size you want the files to be validated based on, you can take help from the table below or enter your desired size in bytes: Size\tBytes 1 MB\t1048576 B - 10242 B - 220 B 2.5 MB\t2621440 B 5 MB\t5242880 B 10 MB\t10485760 B 20 MB\t20971520 B 50 MB\t52428800 B 100 MB\t104857600 B 250 MB\t262144000 B 500 MB\t524288000 B 1 GB\t1073741824 B 2 GB\t2147483648 B "}]