-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: Unexpected data on Writable Stream #1576
Comments
Hello, you're providing a filesystem path to the sharp constructor as the input and then also attempting to pipe data into it; choose one. (The |
I am not sure if I understood, the documentation explains to get a readable stream of the file then use sharp with the readable stream as input then pipe it to the response! but it doesnt matter what I do I get an error. Should I be using Sync methods for this operation? I am basically trying to read an image from the GET response and transform.resize() > pipe it to the response using sharp! |
A Here's you example re-worked to use filesystem paths: const imagePath = "./" + req._parsedOriginalUrl.pathname;
const transform = Sharp(path.resolve(__dirname, imagePath)).resize(200, 200, {
fit: "cover"
}).jpeg({
quality: 20
}).toFile("./"+ req.params.imageName, (err, info) => {
console.log("FILE INFO", info)
}); ...and here's your example re-worked to use a Transform stream: const imagePath = "./" + req._parsedOriginalUrl.pathname;
const read = fs.createReadStream(path.resolve(__dirname, imagePath));
const transform = Sharp().resize(200, 200, {
fit: "cover"
}).jpeg({
quality: 20
});
const write = fs.createWriteStream("./"+ req.params.imageName);
read.pipe(transform).pipe(write); |
This helped me to figure out thanks... in my case I rendered the image on the response so I piped it to the response instead of the write and it works!
|
I've just spotted that this was a cross-post of a question originally asked at https://stackoverflow.com/questions/54635393/render-opmised-images-with-node-js-and-express-with-sharp-or-canvas Please (1) mention existing StackOverflow questions when opening new issues on GitHub and (2) now is a good time for you to update your original StackOverflow question to include the answer to help others. |
I keep getting the error Errors:
Unexpected data on Writable Stream
and
**(sharp:37544): GLib-CRITICAL : 16:05:21.651: g_hash_table_lookup: assertion 'hash_table != NULL' failed
My code is:
Is there anything wrong with my code or is this is an error with the package.
The text was updated successfully, but these errors were encountered: