• 2 months ago
In this video I want to share an approach about how to limit file uploads by format in Django. In my code I'm first verifying by file name if the extension is correct. Then I'm verifying by MIME type.

Gist url: https://gist.github.com/InterTuts/5b3f0eb9d54717606b8d438be75c51f6
Transcript
00:00In this video I'm going to show how to limit file uploads by format.
00:10I will try to upload an image with PNG format.
00:20This is the error message.
00:25Now let's see the code.
00:29From MyView application I'm sending a simple file object using FormData object and Axios.
00:46In Django I'm getting from the request the image and using this function to verify if the image has the expected format.
01:10First I'm verifying by extension.
01:16Then I'm checking if the MIME type of the uploaded image is within a predefined list of allowed types.
01:35Now I have only one format for extension and to add more I will do this.
01:52Finally I will try again to upload same image.
02:00Now the image was uploaded.

Recommended