panoptes-python-client icon indicating copy to clipboard operation
panoptes-python-client copied to clipboard

Improve libmagic MIME-typing solution

Open lcjohnso opened this issue 3 years ago • 1 comments

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
  • ???

lcjohnso avatar Mar 10 '23 19:03 lcjohnso

Current plan:

  • keep libmagic as 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 of warning() -- see https://docs.python.org/3/library/logging.html#logging.Logger.info
    • Use text: "libmagic installation not detected. Media type determination will be based on file extensions."
  • remove imghdr(deprecated from Python 3.13 onward) and adjust implementation to use mimetypes
    • 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)

lcjohnso avatar Feb 21 '25 17:02 lcjohnso

Closed by #321

lcjohnso avatar May 30 '25 20:05 lcjohnso