question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Could not find MIME for Buffer <null>

See original GitHub issue

This is the same as issue 643. However, the latter is closed and seems like it is dead despite people experiencing this issue still.

Expected Behavior

Jimp.read loads an image from a URL correctly.

Current Behavior

Trying to read some images from certain URLs fails, throwing Error: Could not find MIME for Buffer <null>

Failure Information (for bugs)

Whilst certain images load correctly, other consistently fail (a failing url will always fail, without exception).
Example failing URL: https://s-media-cache-ak0.pinimg.com/736x/c9/8f/e1/c98fe17dc7de72bb29c34a0c79ef5762.jpg

Trying to Jimp.read it 1000 times gives:

Called jimp.read() 1000 times.
  Failed: 1000.
  Succeeded: 0.

Steps to Reproduce

Repo with a simple script to reproduce the error: https://github.com/codan84/jimp-bug

Context

  • Jimp Version: 0.6.4
  • Operating System: OSX 10.14.3
  • Node version: v10.16.2

Failure Logs

{ Error: Could not find MIME for Buffer <null>
    at Jimp.parseBitmap (/Users/gruszd01/workspace/jimp-bug/node_modules/@jimp/core/dist/utils/image-bitmap.js:108:15)
    at Jimp.parseBitmap (/Users/gruszd01/workspace/jimp-bug/node_modules/@jimp/core/dist/index.js:498:32)
    at /Users/gruszd01/workspace/jimp-bug/node_modules/@jimp/core/dist/index.js:440:15
    at /Users/gruszd01/workspace/jimp-bug/node_modules/@jimp/core/dist/index.js:168:14
    at /Users/gruszd01/workspace/jimp-bug/node_modules/@jimp/core/dist/request.js:56:9
    at IncomingMessage.<anonymous> (/Users/gruszd01/workspace/jimp-bug/node_modules/phin/lib/phin.compiled.js:1:2100)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19) methodName: 'constructor' }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:28 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
codan84commented, Aug 16, 2019

It’s also worth mentioning that reading the same image using an external request library (I used axios) into a buffer and then loading that same image to jimp from a buffer works.
An example of that is in use-axios branch of the repo I linked above.
This would only mean that there’s an issue with whatever is used for http requests in jimp…

Not working:

jimp.read(failingImageUrl)

Working:

axios({
    method: 'get',
    url: failingImageUrl,
    responseType: 'arraybuffer'
  })
  .then(function ({data: imageBuffer}) {
    return jimp.read(imageBuffer)
  })
3reactions
SaWeycommented, Sep 4, 2019

This is happening when the image requested has a redirect response. Your sample image is returning this response: https://s-media-cache-ak0.pinimg.com/736x/c9/8f/e1/c98fe17dc7de72bb29c34a0c79ef5762.jpg

accept-ranges: bytes
content-length: 0
date: Wed, 04 Sep 2019 10:02:45 GMT
location: https://i.pinimg.com/736x/c9/8f/e1/c98fe17dc7de72bb29c34a0c79ef5762.jpg
retry-after: 0
status: 301
vary: Origin
x-cdn: fastly

jimp does not handle this, neither does phin ❤️.1.0 Either upgrading the phin library ( #https://github.com/ethanent/phin/issues/20) or handling this in the jimp core ‘loadFromURL’ should do the trick.

For now, I updated this code in 'core/dist/index.js to solve my problem:

function loadFromURL(options, cb) {
  (0, _request.default)(options, function (err, response, data) {
    if (err) {
      return cb(err);
    }

    if(response.headers.hasOwnProperty('location') ){
      options.url = response.headers['location'];
      return loadFromURL(options, cb);
    }

    if (_typeof(data) === 'object' && Buffer.isBuffer(data)) {
      return cb(null, data);
    }

    var msg = 'Could not load Buffer from <' + options.url + '> ' + '(HTTP: ' + response.statusCode + ')';
    return new Error(msg);
  });
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find MIME for buffer (null) #643 - oliver-moran/jimp
I have this problem "Could not find MIME for buffer (null)" and i don't know how to fix it. I believe that the...
Read more >
Error: Could not find MIME for Buffer <null> - Stack Overflow
I am doing the same course, and the problem is, that the sample picture (https://timedotcom.files.wordpress.com/2019/03/kitten-report.jpg) ...
Read more >
LQIP generator error- Could not find MIME for Buffer
Hello, I have a website that is having an issue with LQIP. These are JPG and PNG images and when I check the...
Read more >
Got “FAILURE Could not find MIME for Buffer <null>” error if ...
Got “FAILURE Could not find MIME for Buffer <null>” error if using the picture. Got success after using another fig.
Read more >
Send picture telegram - NO USB CAMERA - Node-RED Forum
I know that we can do that with an usb camera but i want to do it another way. ... Error: Could not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found