Тёмный

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

BugBytes
Подписаться 26 тыс.
Просмотров 4,1 тыс.
50% 1

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:
ko-fi.com/bugbytes
▶️ Full Playlist:
• Django Media Files
𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
📖 Blog: bugbytes.io/posts/
👾 Github: github.com/bugbytes-io/
🐦 Twitter: / bugbytesio
📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
File Input: developer.mozilla.org/en-US/d...
Accept Attribute: developer.mozilla.org/en-US/d...
Django FileExtensionValidator: docs.djangoproject.com/en/4.1...
Python-magic: pypi.org/project/python-magic/
#python #django #mediafile

Опубликовано:

 

2 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 28   
@codedjango
@codedjango Год назад
This library is really magical 👍
@seydinaoumarsamabaly1806
@seydinaoumarsamabaly1806 Год назад
Never disappointed with you mate. I learnt somethong new thank you Master 🙌🏾
@bugbytes3923
@bugbytes3923 Год назад
Thanks a lot man, as always!
@valentino7057
@valentino7057 Год назад
Exactly what I needed. Thanks man, you're the best!
@bugbytes3923
@bugbytes3923 Год назад
Thanks a lot for the support!
@SOHAILKHAN-iu8fu
@SOHAILKHAN-iu8fu Год назад
Wow, this video is incredibly informative and eye-opening! I had no idea about these. Thank you so much for sharing and raising awareness on such an important topic. Keep up the great work!
@bugbytes3923
@bugbytes3923 Год назад
Thank you - I'm glad that the video was useful!
@user-wb5hj3qn5x
@user-wb5hj3qn5x 7 месяцев назад
Thanks man ,very very good
@bugbytes3923
@bugbytes3923 7 месяцев назад
Thanks a lot man!
@ganiyevuz
@ganiyevuz Год назад
thanks this was useful for me 👍👍
@bugbytes3923
@bugbytes3923 Год назад
Thank you for watching!
@iwswordpress
@iwswordpress 5 месяцев назад
Excellent! My go to channel for Django :)
@bugbytes3923
@bugbytes3923 5 месяцев назад
Awesome - Thanks a lot for watching!
@digital-tree
@digital-tree Год назад
excellent video, congratulations on the didactics
@bugbytes3923
@bugbytes3923 Год назад
Thanks a lot!
@dodokwak
@dodokwak Год назад
Thx a lot. Small note about unit testing: if you used a generated file for the test you can get a TypeError (expect string but not imagefield file as 10:25 expects a path to the file. I've solved it by changing param to a file for reading bytes.
@user-co1bc6iq9r
@user-co1bc6iq9r Год назад
Hey man I spent a week thinking on how best to do content validation of a file. This was very helpful, once step closer to completing the goal.
@bugbytes3923
@bugbytes3923 Год назад
Hey - thanks, glad to hear it was helpful. Thanks for watching! Good luck in your project.
@TomislavMiletic
@TomislavMiletic 11 месяцев назад
One more great video, which is not a surprise, thank you! Can you please tell me, considering the options presented, is it enough to use only the 3rd option?
@bugbytes3923
@bugbytes3923 11 месяцев назад
Thank you! I would recommend all 3. Even adding the "accept" attribute in HTML can prevent unwanted uploads that will be rejected on your server. Anything to prevent unnecessary load on the server (plus associated costs) is a win! By only using the 3rd option, users will find it easier to upload the wrong file types, which the server then processes and rejects - that load can be avoided with the other two methods.
@TomislavMiletic
@TomislavMiletic 11 месяцев назад
@@bugbytes3923 thank you
@frameff9073
@frameff9073 Год назад
thank
@bugbytes3923
@bugbytes3923 Год назад
You're welcome!
@Coden69
@Coden69 Год назад
Wowww
@hjs9693
@hjs9693 7 дней назад
Thank you for your video. im curious why just use 1024 bytes in from_buffer? Is this based on something that data or books?
@bugbytes3923
@bugbytes3923 6 дней назад
Thank you. No real reason to choose that number, just for demo.
@TomislavMiletic
@TomislavMiletic 10 месяцев назад
Came back to post another comment, so i have implemented this but when trying to deploy to railway app, the build breaks on this python magic bin library. Any advice? Is there another way to do the same thing?
@bugbytes3923
@bugbytes3923 10 месяцев назад
Ah - sorry to hear that. Do you have an error log for this issue? I've not used Railway, but might be able to help.
Далее
django-htmx - Django Extensions for Working with HTMX
37:06
HELLUVA BOSS - THE FULL MOON  // S2: Episode 8
23:10
How to Create INTERACTIVE MAPS in Python
3:24
Просмотров 2,6 тыс.
Django Database Transactions / atomic() function
34:15
Просмотров 4,2 тыс.
Django & HTMX - Dynamic Form Creation and Submission
24:36
5 New AI Tools You Should Try
9:18
Просмотров 12 тыс.