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.
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) {
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
Most helpful comment
Hello, the
requestmodule expectsencodingto be set to receivebodyas aBuffer.https://github.com/request/request#requestoptions-callback