If you need to proxy content types like multipart/form-data or text/event-stream using @fastify/reply-from, you must prevent Fastify from parsing them. If the body is parsed, it is consumed and cannot be forwarded to the upstream server.
You can achieve this by registering custom content type parsers that pass the raw body through using fastify.addContentTypeParser.
// Register custom content type parsers that pass raw body through
fastify.addContentTypeParser('multipart/form-data', function (req, body, done) {
done(null, body)
})
fastify.addContentTypeParser('text/event-stream', function (req, body, done) {
done(null, body)
})
fastify.register(require('@fastify/reply-from'))
fastify.post('/upload', (request, reply) => {
// The multipart data will be proxied as-is to the upstream server
reply.from('http://upstream-server.com/upload')
})
fastify.post('/events', (request, reply) => {
// The SSE data will be proxied as-is to the upstream server
reply.from('http://upstream-server.com/events')
})