Django Media Files - Restricting Uploadable File Types with Validators and python-magic

Django Media Files - Restricting Uploadable File Types with Validators and python-magic

6.125 Lượt nghe
Django Media Files - Restricting Uploadable File Types with Validators and python-magic
In this video, we will look at how to restrict the types of files that can be uploaded by users in our Django applications. We will see three methods on how to restrict this data: * Using file input's 'accept' parameter * Using Django's FileExtensionValidator * Using python-magic to verify the contents of the file match the extension. We'll also see how to write a custom validator in Django and add multiple validators to a single Model field. 📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀: 00:00 Intro 02:27 File Input accept attribute 06:03 Adding Django FileExtensionValidator to model FileField 10:09 Using python-magic in Django Validator to check file content ☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲: To support the channel and encourage new videos, please consider buying me a coffee here: https://ko-fi.com/bugbytes ▶️ Full Playlist: https://www.youtube.com/playlist?list=PL-2EBeDYMIbQpw0N1BmAi9-acwhpxEfoo 𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮: 📖 Blog: https://bugbytes.io/posts/ 👾 Github: https://github.com/bugbytes-io/ 🐦 Twitter: https://twitter.com/bugbytesio 📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻: File Input: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file Accept Attribute: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept Django FileExtensionValidator: https://docs.djangoproject.com/en/4.1/ref/validators/#fileextensionvalidator Python-magic: https://pypi.org/project/python-magic/ #python #django #mediafile