I have a backend go fiber server which would serve files fetched from cloud service using minio client sdk. My goal is to achieve video file streaming with out exposing direct connection to cloud url and the video must be seekable, both forward and backward (same functionality as cloud's url). However, when I add the stream sent from the server, the video just can not be seeked or sometime only backwards seek. I tried to set the response's Content-Length, Content-Type, Content-Range, etc... and it just won't work. Notes: all behaviors happened in chrome latest stable version and not firefox or postman. Here is my code:
// c is the *fiber.Ctx
object, err := minioClient.GetObject(context.Background(), bucketName, fileName, minio.GetObjectOptions{})
if err != nil {
return err
}
objInfo, err := object.Stat()
if err != nil {
return err
}
buffer := make([]byte, objInfo.Size)
object.Read(buffer)
c.Set("Content-Length", fmt.Sprintf("%d", objInfo.Size))
c.Set("Content-Type", "video/mp4")
c.Set("Connection", "keep-alive")
c.Set("Content-Range", fmt.Sprintf("bytes 0-%d/%d", objInfo.Size, objInfo.Size))
c.Response().SetBodyStream(bytes.NewReader(buffer), int(objInfo.Size))
return nil
//c.SendStream just won't work