Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Unsupported MIME type: #26

Open
maka-io opened this issue Aug 12, 2017 · 19 comments
Open

Error: Unsupported MIME type: #26

maka-io opened this issue Aug 12, 2017 · 19 comments

Comments

@maka-io
Copy link

maka-io commented Aug 12, 2017

//app/node_modules/node-thumbnail/src/thumbnail.js:44
throw err;
^

Error: Unsupported MIME type:
at Jimp.throwError (//app/node_modules/jimp/index.js:82:43)
at Jimp.parseBitmap (//app/node_modules/jimp/index.js:307:31)
at //app/node_modules/jimp/index.js:200:29
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

Steps to reproduce:
Follow the readme.

@honza
Copy link
Owner

honza commented Aug 12, 2017

What's the file type of the file you tried to convert?

@honza
Copy link
Owner

honza commented Aug 12, 2017

This happens when the file you're trying to convert is in an unsupported format.

@levidrain
Copy link

I'm getting the same issue. I've had this problem before and I thought that was the reason for the addition of the -i flag.

@chrisnx
Copy link

chrisnx commented Sep 11, 2017

I'm also getting the same issue. -i the flag does not appear to make a difference.

@honza
Copy link
Owner

honza commented Sep 11, 2017

Could any of you create a minimal project to demonstrate the problem? And include the file you're trying to convert? Thanks

@chrisnx
Copy link

chrisnx commented Sep 11, 2017

I might have time later today, but here's the error I'm getting which may help.

user/src/app/node_modules/node-thumbnail/src/thumbnail.js:44
server_1    |       throw err;
server_1    |       ^
server_1    | 
server_1    | Error: Unsupported MIME type: 
server_1    |     at Jimp.throwError (/user/src/app/node_modules/jimp/index.js:82:43)
server_1    |     at Jimp.parseBitmap (/user/src/app/node_modules/jimp/index.js:307:31)
server_1    |     at /user/src/app/node_modules/jimp/index.js:200:29
server_1    |     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:446:3)

Happens on any file that is not '.jpg' '.jpeg' or '.png'

@honza
Copy link
Owner

honza commented Sep 11, 2017

OK, cool. Are you trying to convert files like .tiff or .bmp, or is it throwing the error on non-image files like .pdf or .psd or .doc?

@chrisnx
Copy link

chrisnx commented Sep 12, 2017

.gif mainly, (but also .pdf, .txt etc, to see if it would skip it)

@honza
Copy link
Owner

honza commented Sep 12, 2017

The underlying resizing library only seems to support jpg, png, and bmp. Looking at alternatives now.

@chrisnx
Copy link

chrisnx commented Sep 13, 2017

Thanks! .gif support would be ideal.

@ziwar
Copy link

ziwar commented Apr 11, 2018

If the file is not supported it will crash the app even if you put it inside a try catch handler. Even Sentry do not catch it. I had an image with a jpg extension but for some reason the mime type was image/vnd.adobe.photoshop instead of image/jpeg. and that image was crashing the app no matter what. The only way I was able to prevent the app from crashing is by removing the code: throw err; from line 46. This is a problem because if you allow users to upload files they will crash the app because the uploader will think they are uploading a jpg file. while the mime type might be something else. Maybe, instead of throwing the error, can we return a callback with the error as a parameter?

@nkogit
Copy link

nkogit commented Jan 12, 2019

I had this problem with unsupported file types (like docx, pdf, ai) and using the ignore: true option. I believe there's a bug in line 158, it should read
if (!isValidFilename(image) && settings.ignore) {
instead of
if (!isValidFilename(image) && !settings.ignore) {

@chrisdopuch
Copy link

I ran into the same issue with a .json file in my images directory, and after digging into the source code came to the same conclusion as @nkogit , it appears that the ! in front of settings.ignore should be removed. This will cause invalid files not to be passed to jimp, which will avoid the mime type error. Patching the code like this in my node_modules did indeed resolve my problem with the JSON file.

@honza
Copy link
Owner

honza commented Jan 21, 2019

Cool, I'll take a look shortly.

@honza
Copy link
Owner

honza commented Jan 21, 2019

I just did this test with the latest master:

$ ls test-src/
DSC_7281.JPG  hi.pdf

$ node bin/thumb test-src test-dest 
ERROR: Your source directory contains unsupported files: hi.pdf

$ node bin/thumb test-src test-dest --ignore
Processing DSC_7281.JPG
All items have been processed.

$ ls test-dest/
DSC_7281_thumb.JPG

It seems to work properly, IMO.

@chrisdopuch
Copy link

Thanks for checking @honza. Unfortunately I am still experiencing the mime type error with a JSON file on the latest release. Here is a pretty minimal test case that shows the problem: https://github.com/chrisdopuch/node-thumb-26-repro

Just run yarn && yarn start and you will see:

yarn run v1.13.0
$ thumb --ignore images images
/mnt/c/app-projects/node-thumb-26-repro/node_modules/node-thumbnail/src/thumbnail.js:46
      throw err;
      ^

Error: Unsupported MIME type:
    at Jimp.throwError (/mnt/c/app-projects/node-thumb-26-repro/node_modules/jimp/index.js:82:43)
    at Jimp.parseBitmap (/mnt/c/app-projects/node-thumb-26-repro/node_modules/jimp/index.js:307:31)
    at /mnt/c/app-projects/node-thumb-26-repro/node_modules/jimp/index.js:200:29
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If you delete the JSON file in the images directory, then you don't hit the error.
I also tried with a PDF file as well, but I got the same error (just for type pdf):
Error: Unsupported MIME type: application/pdf

Let me know if I can help in any way, thanks for writing this useful tool 👍

@honza
Copy link
Owner

honza commented Jan 22, 2019

Wow, thanks for the great reproduction case. This is super helpful.

I had a look, and it looks like you're not using the latest code. The latest changes haven't been published to npm yet.

I changed the package.json file like this,

diff --git a/package.json b/package.json
index 61cae6c..0666649 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,7 @@
   "version": "1.0.0",
   "license": "MIT",
   "dependencies": {
-    "node-thumbnail": "^0.14.0"
+    "node-thumbnail": "git+https://[email protected]/honza/node-thumbnail.git"
   },
   "scripts": {
     "start": "thumb --ignore images images"

And then the latest master is installed.

Then running the start command:

$ npm start

> [email protected] start /home/honza/GitHub/node-thumb-26-repro
> thumb --ignore images images

Processing image.jpg
All items have been processed.

@honza
Copy link
Owner

honza commented Jan 22, 2019

I just published 0.15.0.

@chrisdopuch
Copy link

Awesome! Confirmed working with my json files now. Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants