0

I use sharp on Hook to resize images on the fly in fastify.

fastify.addHook('onSend', async (request, reply, payload) => {
          const newPayload = await sharp(payload.filename).resize(200, 100).toFormat('jpg').toBuffer();
         return newPayload
      })

But when I run this code

enter image description here

I see 5 seconds between finished resize and killed some process bu Nodejs at the end.

After it I get image into browser.

Can you explain this behaviour?

Alexufo
  • 1,723
  • 1
  • 15
  • 30
  • did you try the [stream](https://www.npmjs.com/package/sharp#stream) interface? The 5 sec seems a timeout to me – Manuel Spigolon Sep 25 '19 at 15:23
  • @ManuelSpigolon maybe I did mistake with example.I get empty response. Anyway I added this functionality to route without hook and works very good. resizing works like without resizing. Yes. It is timeout. But I can understand why on hook I get timeout, – Alexufo Sep 25 '19 at 23:39
  • I think the content-length is not updated – Manuel Spigolon Sep 26 '19 at 07:06

0 Answers0