var resizer = sharp().resize( 300, 300 ).withoutEnlargement().max().toFile( 'public/img_thumbs/' + thumb_name, ( err, info ) =>
{
console.log( err );
});
request( url ).pipe( resizer );
Any idea why I'm getting "Error: Input buffer contains unsupported image format" for remote images like these?
I realize that maybe it's more of a request module issue but I can't figure out how to fix it specifically with sharp, besides the request response.headers['content-type'] returns correctly "image/jpeg".
Hello, please see #930
I checked out the request documentation and tried that before posting here, but still no luck with those urls. Code as follows:
var resizer = sharp().resize( 300, 300 ).toFile( 'public/imgs/image.jpg', ( err, info ) =>
{
console.log( err );
});
request( { url, encoding: null } ).pipe( resizer );
This still outputs "Input buffer contains unsupported image format".
It is worth mentioning that using the image referenced in #930
(https://padletuploads.blob.core.windows.net/dev/2/1d5f5e1d281a2145aae25595d050e77b/JPG_Image.jpg) I have no issues at all.
I solved it and it was the craziest thing!
Those url strings, coming from html input forms, had url encoded ampersands!
@pig-cop Could you share how you actually solved it? I'm having the same issue.
Just in case anyone stumbled over this problem.
I used superagent to pipe the response directly to sharp.
I had the problem that this unhandled error crashed express every time someone uploaded a faulty image. try/catch didn't help.
Here is how I fixed it:
const request = require('superagent');
// ...
request({url, method: 'GET'}).pipe(transformer).on('error', (e) => {
console.log(e);
}).pipe(res);
This will gracefully handle the error.
Most helpful comment
@pig-cop Could you share how you actually solved it? I'm having the same issue.