Single file type for multiple content types? Follow
Please sign in to leave a comment.
You can use the FileTypeDetector extension point to dynamically determine the content type of a file.
Thanks! That definitely looks promising. I'm trying to implement this now but my implementation is never getting invoked. Debugging a bit I see that in FileTypeManagerImpl.getOrDetectFromContent(), these files are being auto-detected as text or binary before it would consult my implementation. Is there something I need to do to force it to skip auto-detection on these files and invoke my detector?
Try to invalidate caches? I think the detected file type is persisted and not updated when a new detector is registered.
That seems to have done it! One more question along these lines...is there any common facility in IDEA to resolve a MIME type/content type to a file type (or even a file extension)?
UPDATE: I do see HtmlUtil.CONTENT_TYPES which uses MimeTypeDictionary, but that's just a list of MIME/content types, not a map from them to standard extensions. I saw a few third-party libs that can do this, but before I pull one into my project, I wanted to see if this IDEA had this out-of-the-box.
UPDATE 2: I went ahead and used Apache Tika 1.8 (just the core jar) for this purpose and it's working wonderfully. Obviously if IDEA has such a provision internally, that would be even better, but at this point I think I'm good to go!