Search code examples
goffmpegstreamhttpservergo-fiber

Is it possible to read streaming response body using fiber?


I have a streaming server(ffmpeg) that send data through HTTP. I sent the stream to my fiber backend but I only have access to c.body() when the stream server(ffmpeg) is terminated. Is there any way to capture streamed data in real-time in fiber?

here is my sample code:

package main

import "github.com/gofiber/fiber/v2"

func main() {
  app := fiber.New()
  
app.Post("/", func(c *fiber.Ctx) error {
    golang        // real-time reading streamed data in c.body() and send it to fiber websocket
        return c.SendStatus(200)

}

Solution

  • It looks like what you want can be found in c.Context() - this returns the FastHTTP context that Fiber uses under the hood.

    The FastHTTP context has at least 2 functions which sound like they're what you're after: SetBodyStream and SetBodyStreamWriter.

    Related fiber docs

    FastHTTP docs