FileGetMimeType() for .m4a throws java.lang.NullPointerException

Description

When calling FileGetMimeType("#createuuid()#.m4a"), I get a java.lang.NullPointerException. However, if I make the same call using an mp3 file (or jpg, gif, mp4, etc), it returns the correct mime type. In either of these cases, the file does not actually exist.

When I call FileGetMimeType("C:/mytestfile.m4a") and the file exists, and is really a text file, the function returns "text/plain" so the function appears to be reading the file - perhaps this happens for certain file extensions?

Does the source file need to exist for this call to work correctly?

Environment

Windows 7

Activity

Show:

Michael Offner 3 December 2018 at 08:26

i like your approach, i will adapt it with a little change.
we need to prefer metadata from reading the file itself, not all file with the same extension necessary have the same mimetype. in addition it need to work in case we feed a file like "temp.tmp".

This is the reason with did limit to reading the file in the first place.

Bruce Kirkpatrick 30 November 2018 at 02:57

I wanted to help with bugs that aren't mine for fun.

Here is the expected fix he's asking for:
https://github.com/brucekirkpatrick/Lucee/commit/94497f6186d056cea5194a3bcf77dc6413623953

I added support so Tika can be used to detect with either file path as string or resource. There was nothing in the other classes to allow string based version yet. I tested both cases and it still works.

JP 21 November 2018 at 07:05

If I'm reading your change correctly, it would now be throwing an error when the file doesn't exist. Correct? If so, you would be breaking code that doesn't expect the file to exist, i.e. some of my code

This function currently does not throw an error when getting the mime type of (at least) a subset of common file types (based on the file extension) with the names like #CreateUUID()#.jpg, #CreateUUID()#.txt, #CreateUUID()#.mp4, etc. Setting the strict argument to false (it's defaulted to true), should only check the file extension. Docs read: "if set to true, Lucee checks the header of the file, when set to false, Lucee only checks the extension."

Pothys - MitrahSoft 21 November 2018 at 06:42

Added the fix too.

Pull request: https://github.com/lucee/Lucee/pull/608

Fixed

Details

Assignee

Reporter

Priority

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Affects versions

Created 18 November 2018 at 16:54
Updated 18 March 2019 at 16:40
Resolved 3 December 2018 at 10:10