Jimp: [Error: Unsupported MIME type: application/octet-stream]

Created on 5 Jan 2016  路  16Comments  路  Source: oliver-moran/jimp

hi , I have got this error when I try to resize uploaded picture .
I print out the file object I try to resize.

avatarFile  is  { fieldname: 'avatar',
  originalname: 'IMG_3242.jpg',
  name: 'ae08b661d41e2cc9bac647765a9f2aed.jpg',
  encoding: '7bit',
  mimetype: 'image/jpeg',
  path: '/var/folders/sd/l6z16nv17txfs7n_x0v2r8r40000gn/T/ae08b661d41e2cc9bac647765a9f2aed.jpg',
  extension: 'jpg',
  size: 652690,
  truncated: false,
  buffer: null }

and when I read avatarFile , I got [Error: Unsupported MIME type: application/octet-stream] , do u hv any idea about this issue? thanks

jimp.read(avatarFile.path ,function(err,image){
  ...
})
bug enhancement

Most helpful comment

Hello,
Not the same but something similar here: .write() will throw this error when the folder path doesn't exist. It also happens when i try to write a filename without extension. I'm just making sure that the folder path is created. Have you tried fs.exists() on that path? maybe it's a permission problem.
Greetings

All 16 comments

Hello,
Not the same but something similar here: .write() will throw this error when the folder path doesn't exist. It also happens when i try to write a filename without extension. I'm just making sure that the folder path is created. Have you tried fs.exists() on that path? maybe it's a permission problem.
Greetings

@yangshenhuai sorry for the delay getting back to you. I'm mega busy IRL for the next month and a half.

Did you verify what file is (or is not) at avatarFile.path. What the error is telling you is that the file that it reads is application/octet-stream MIME type. And not a JPEG, PNG or BMP.

I had the same problem. I managed to solve it by simply rechecking the path and making sure that the directory exists. Make sure to check and make sure that all directories mentioned in the path exists /var/folders/sd/l6z16nv17txfs7n_x0v2r8r40000gn/T/

Cheers

Error handling could be improved, I guess.

This problem is relevant when you have a buffer that you want to save, and you know mimetype, but don't have the file name. For example when you receive form data in a http endpoint. I used multer for that, and it provides me with buffer and mimetype, so I could set it manually, but there is no config or method for that.

I have the same problem, fb changed some urls today and I am not able to do this:

Jimp.read('https://lookaside.facebook.com/platform/profilepic/?psid=1587355968026286&height=1024')

Error: Unsupported MIME type: application/octet-stream
at Jimp.throwError (/var/app/dvel-api-ocean/service_bot/node_modules/jimp/index.js:61:44)
at Jimp.parseBitmap (/var/app/dvel-api-ocean/service_bot/node_modules/jimp/index.js:410:31)
at /var/app/dvel-api-ocean/service_bot/node_modules/jimp/index.js:259:29
at Request._callback (/var/app/dvel-api-ocean/service_bot/node_modules/jimp/index.js:88:24)

Any idea how to fix this?

@phips28 You could try receiving the data from the URL as a Buffer and then passing to Jimp. For example, using got:

const Jimp = require('jimp');
const got = require('got');

const url = "https://lookaside.facebook.com/platform/profilepic/?psid=1587355968026286&height=1024";

// Setting encoding to null ensures getting back a Buffer.
got(url, { encoding: null }).then(data => {
    return Jimp.read(data.body);
}).then(image => {
    image.write('test.jpg');
});

You can also double check that the MIME is appropriate before passing to Jimp by checking data.headers['content-type'] (will not be octet-stream but rather whatever the true type is) but that might be overkill since Jimp will verify when reading the Buffer.

I think that in the future, Jimp should be made able to handle this case naturally without having to go outside of it.

@czycha I found the issue.

facebook returned a HTML page when there was is headers.user-agent sent.
data.headers['content-type'] = text/html

After adding the user agent in the defaults, it works with Jimp.

var Request = require('request').defaults({
    encoding: null,
    headers: {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.46 Safari/537.36"
    }
});

But I found no solution to configure the user agent for Jimp, without forking. Do you know something?

@phips28 Unfortunately, I don't believe there's a way to modify the default headers for Jimp without forking. As it stands, you can either use your fork or run the request using proper headers and pass the resulting buffer to Jimp like in my example.

I also have a similar problem with the read function.

i am trying to read a buffer
let photo = await jimp.read(file.buffer)

the buffer contains:

mimetype: 'image/jpeg',
  buffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 48 00 48 00 00 ff e1 00 80 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 04 01 12 00 03 00 00 00 01 00 01 ... >,

but the error says:
Unsupported MIME type: application/octet-stream

it used to work and i didn't change any code.
Any thoughts?

I switched to jimp2 and that seems to work

@bpikaar didnt know there is a jimp2

I have to check that out. thx.

edit: jimp2 is 2 years old?

@phips28 @bpikaar can i get a url that works? all the ones in this thread don't resolve to anything @czycha

closing in favor of #267

You are having a similar error. After the conversion the buffer is like application / octet-stream instead of image / jpeg. To resolve it, just do this:

.getBuffer(jimp.MIME_JPEG, (err, buffer) => {
const newBuffer = new File([buffer], this.photoName, {type: "image/jpeg"})
this.photoFile = newBuffer
})

Was this page helpful?
0 / 5 - 0 ratings

Related issues

codan84 picture codan84  路  25Comments

tonysamperi picture tonysamperi  路  15Comments

fabiusss picture fabiusss  路  14Comments

RomainFallet picture RomainFallet  路  26Comments

Gustavo6046 picture Gustavo6046  路  15Comments