Mimetype –stdin always returns text/plain

Posted on

Problem :

I am having a hard time getting the correct mimetype info without relaying on the file extension / inode data. When using magic it returns with text/plain ever time regardless of what the file is.

For some background information.

When I allow linux mimetype to use glob and its other methods it works correctly.

mimetype mountain.jpg

mountain.jpg: image/jpeg

When I try to have it work with magic checking because i want to really make sure this file is an image it tells me its a text file

mimetype -M mountain.jpg

mountain.jpg: image/jpeg

To make sure its not a text file I will use the file command

file -i mountain.jpg

mountain.jpg: image/jpeg; charset=binary

If i try one of the following I will now only be able to get text/plain.

cat mountain_dew-400-400.jpg | mimetype -M --stdin

STDIN: text/plain

tee mountain_dew-400-400.jpg | mimetype -M --stdin

STDIN: text/plain

mimetype --stdin - < mountain_dew-400-400.jpg

STDIN: text/plain

I have already run the following commands

cpan install IO::Scalar
cpan install File::MimeInfo
cpan install File::MimeInfo::Magic

Solution :

mimetype --stdin does not appear to work at all. I’ve submitted Debian bug #784545.

As a workaround you can use file -i - instead of mimetype --stdin.

Leave a Reply

Your email address will not be published. Required fields are marked *