Improve libmagic MIME-typing solution
Multiple teams have run into issues with the Client's current libmagic based MIME-typing solution for non-image media. In most cases, the libmagic installation was to blame: namely, the need to install of the underlying C library in addition to the python-magic package.
Solution 1: Improve documentation to note the need for C library installation with instructions on how to execute this install. Also consider adding check for presence of C library (e.g., via ctypes.util.find_library('magic')) with explanatory error if one is not found.
Solution 2: Replace libmagic based MIME-typing with another solution. As discussed in #210, options include:
- Use existing library for MIME-typing via extension (e.g.,
mimetypes) - Write manual extension-to-MIME mapping function, mirroring that used by the lab's subject uploader in PFE
- ???
Current plan:
- keep
libmagicas primary MIME-typing solution (good to reflect on file data rather than trusting extension is accurate), but tone down the feedback info provided to the user.- Use
info()instead ofwarning()-- see https://docs.python.org/3/library/logging.html#logging.Logger.info - Use text: "
libmagicinstallation not detected. Media type determination will be based on file extensions."
- Use
- remove
imghdr(deprecated from Python 3.13 onward) and adjust implementation to usemimetypes- Test all Zooniverse-supported mimetypes for compatibility (see list here: https://github.com/zooniverse/Panoptes-Front-End/blob/master/app/pages/lab/subject-set.cjsx#L20)
Closed by #321