P
P
Pavel Dyukarev2019-02-24 01:55:21
Django
Pavel Dyukarev, 2019-02-24 01:55:21

What's the best way to check the extension of an uploaded file in Django?

Guys, tell me please.
There is an application in Django.
Models store two files - mp3 and jpg/png.
It is necessary that the user can download only these formats. Other formats ogg, gif, etc. should be banned from uploading.
I read on the Internet that you can arrange validation with JS using the HTML5 - File API.
And you can use the magic of Django (I really haven’t figured it out yet)
Tell me the best practice, its pros and cons. I need to choose an option, but so that I know about the pitfalls.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2019-02-24
@PavelDuk

Google file header.
For example:

3.1. PNG file signature
The first eight bytes of a PNG file always contain the following (decimal) values:
137 80 78 71 13 10 26 10

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question