Home > Net >  go - How can you serve static files with route based authorization with JWT in Gin?
go - How can you serve static files with route based authorization with JWT in Gin?

Time:11-28

I am trying to serve videos from a directory. I know how to do that (r.Static("/videos", "./videos")) but I have a directory for each user in there like /videos/testuser/video.mp4. I have implemented a login system with JWT, but how would I got about only letting testuser access /videos/testuser and user1 access /videos/user1?

Thanks!

CodePudding user response:

Store the UserID in JWT and parse the JWT claims whenever someone downloads the video. Use fmt.Sprintf("videos/%s/video.mp4", jwt.UserId) to get the desired directory depends on different user.

  • Related