Sharp: Input file is missing or of an unsupported image format

Created on 3 Sep 2017  路  2Comments  路  Source: lovell/sharp

I'm getting the above error when using the response from a request call for constructing the sharp object.

const url = "https://padletuploads.blob.core.windows.net/dev/2/1d5f5e1d281a2145aae25595d050e77b/JPG_Image.jpg"
request(url, function(error, response, body) {
  if(!error) {
    sharp(body).rotate().resize(300,300).toBuffer().then(function(data) {
      console.log("Done")
    })
  }
})

I've checked the URL and it returns a valid image.
In fact, when using streaming, things work. E.g.

//THIS WORKS
const url = "https://padletuploads.blob.core.windows.net/dev/2/1d5f5e1d281a2145aae25595d050e77b/JPG_Image.jpg"
const pipeline = sharp().rotate().resize(300,300)
request(url).pipe(pipeline)

I tried to wrap the body variable in a new Buffer(body, "binary") call but that did not help either. It just gave me a different error message: Input buffer contains unsupported image format

Wondering what I am doing wrong.

question

Most helpful comment

Hello, the request module expects encoding to be set to receive body as a Buffer.

- request(url, function(error, response, body) {
+ request({ url, encoding: null }, function(error, response, body) {

https://github.com/request/request#requestoptions-callback

All 2 comments

Hello, the request module expects encoding to be set to receive body as a Buffer.

- request(url, function(error, response, body) {
+ request({ url, encoding: null }, function(error, response, body) {

https://github.com/request/request#requestoptions-callback

I'm getting the same error, but I try to use the input stream returned by the Google Cloud Storage File object: File.createReadStream, which returns a readable stream. Any tips? https://stackoverflow.com/questions/48960700/how-to-run-sharp-transform-on-readable-http-stream-and-write-tofile

Was this page helpful?
0 / 5 - 0 ratings