1 year ago

#66881

test-img

Sun

Stream files from CDN via a springboot app acting as a reverse proxy

I have a springboot app that acts as a reverse proxy between a client (browser) and blobstore resources which are videos. I need to be able to play these videos in the browser via streaming. The reason I have this setup is I need to handle some custom authorization logic on the server side.

To do this, I have this GET API:

  @GetMapping(API_CONTENT_PATH + "/{id}")
  public ResponseEntity<byte[]> getVideoById(@PathVariable("id") String id, HttpServletRequest httpServletRequest) {
    try {
      return _videoService.getVideoContentResponse(id, httpServletRequest);
    } catch (Exception e) {
      log.error("", e);
    }

    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
  }

In the videoService.getVideoContentResponse, I simply create a new request using RestTemplate and send the request headers passed in httpServletRequest.

The RestTemplate.exchange then proceeds to download the ENTIRE file instead of streaming it.

And this is what I would like to solve. How do I stream files from blobstore via a springboot app acting as a reverse proxy?

spring-boot

video-streaming

streaming

0 Answers

Your Answer

Accepted video resources