Search code examples
pythonzipmime-types

How to detect mime type of files in python?


I have a problem such that i have zip files uploaded from forms and i want to detect the mime type of the files that contained in these zip files,i have no problem in extracting the files from the zip but the problem how to know the mime type of each file in this zip?Thanks


Solution

  • You can use the Python built-in mimetypes module for this. I believe this module relies solely on the file name and not its contents.