-
-
Notifications
You must be signed in to change notification settings - Fork 764
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: Could not find MIME for Buffer <null> #775
Comments
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. Not working:
Working:
|
Have same problem. Problematic images downloaded on local disk with requst module make this error in jimp too. But are not have visible promplems. |
I try use GM for edited this images. It don't read them too. Show this error: How i can get images from internet and use them with JIMP without errors ? |
I'm facing the same issue using node-vibrant, a library that uses Jimp and the axios trick is working like a charm! |
This is happening when the image requested has a redirect response.
jimp does not handle this, neither does phin <3.1.0 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);
});
} |
Please make a PR so we can all benefit from your code :) A comment helps very few but a PR can help many |
But what i can't use downloaded images from this urls. Are not looking broken or something. Opened with any program for images viewer. |
Since there were 2 options I didn't know what way to go, but I have created a pull request which allows following redirects without upgrading phin. |
If phin supports this in a later version it think it makes sense to upgrade |
It probably does make sense, but it also makes sense to always follow redirects by default. |
* Follow redirects Fixes #775 * Follow redirects Fixing lint error * Follow redirects Fix tests * Added redirect test * Fixed lint errors * Skip redirect test in browser as we cannot mock a server * Different test for browser * Fixed browser detection
🚀 Issue was released in v0.9.3 🚀 |
🚀 Issue was released in v0.9.3 🚀 |
Getting same in still now
{ Error: Could not find MIME for Buffer |
I still get this error
My codes use to add logo-img to picture
|
I'm also seeing this "Error: Could not find MIME for Buffer " error sporadically one time in about 5 or so. In my case, the images are local files (no network access involved). I'm working to extract a small test case from the larger test suite to submit for repro. Current versions of jimp 0.10.2 and node 13.12.0 |
I'm also seeing this "Error: Could not find MIME for Buffer " error. the images are buffers. |
So, after much digging and experimentation I rewrote all of my code that creates the local files and all of the invocations of jimp to process them to absolutely guarantee there was no possibility of any async race conditions or any possibility of reusing intermediate files. That appears to have resolved my issues as far as I can tell under test. |
I also face this issue.. Any news on this old issue? |
Same here... |
After rewriting all of my code that calls jimp as noted above, I no longer have these problems. I believe I can now confirm that the issues I was having were race conditions between jimp code and the file system. |
Facing the same issue trying to read from a local file. |
Hi ! I could upgrade the JIMP version and now i can upload the image correctly. |
I'm also getting this issue, perhaps worth re-opening?
|
Maybe this is of help to others. I got this error and solved it in my script. In my case it was an async bug in my code. When doing batch processing I was trying to run jimp.read() on an image file that was not found, incomplete or empty at the run time. |
@codan84 your solution works for me thanks so much |
Thank You This worked for me |
Instead of using axios, you can use node-fetch to turn the image into a buffer and then feed it to jimp import fetch from "node-fetch";
const res = await fetch(inputURL);
// I turn the image to a buffer and then to a Jimp image, otherwise some images are not processed
const data = await res.arrayBuffer();
const photo = await Jimp.read(data); This solved my issue. |
I just had this error, and in my case the solution was simple. I was using a command line tool to generate a png from a PDF, and for some images it worked and others it broke, but it turned out I just needed to add a 1 second delay between generating the png and trying to load it. I guess the generation program finished before the png was entirely ready or something like that (after finding a fix, I did not follow up on the details). |
Further confirmation that this is a race condition.
…On Thu, Apr 13, 2023 at 05:17 bruceceng ***@***.***> wrote:
I just had this error, and in my case the solution was simple. I was using
a command line tool to generate a png from a PDF, and for some images it
worked and others it broke, but it turned out I just needed to add a 1
second delay between generating the png and trying to load it. I guess the
generation program finished before the png was entirely ready or something
like that (after finding a fix, I did not follow up on the details).
—
Reply to this email directly, view it on GitHub
<#775 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUCPK7AJXEMCJQHGWT773XA7ABJANCNFSM4IME63AQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I maintain a server that produced this issue in production 79 times within a few days on an endpoint handling file uploads (so the buffer is coming from an uploaded file). Unfortunately I can't provide any sample data since it's in production, but if there's anything I can do to help narrow down the issue please let me know. It doesn't seem to be causing us major issues (just sometimes a thumbnail doesn't show, I presume), so it's not our priority, but I'd be happy to help if I can. |
If you have a solution I have the ability to merge! |
… retrieve the image from the given URL. This buffers the image data which is then given in the input argument to the Jimp.read() function. This fixes a common issue with this function when the URL is given as the input argument where it fails to retrieve the image, resulting in the error, "Could not find MIME for Buffer", see jimp-dev/jimp#775. In this link there is a suggestion to use axios to fix the issue, this suggestion has been implemented here.
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:Steps to Reproduce
Repo with a simple script to reproduce the error: https://github.com/codan84/jimp-bug
Context
Failure Logs
The text was updated successfully, but these errors were encountered: