0

I am currently working on a microservice which only job it is to work as a repository for audio tracks. It's a bit more complicated than that but essentially you can upload e.g. an MP3 to it and then request it in order to play it.

Until now I had my Spring Boot server take care of all that. It took the file, converted it, uploaded it to a GCS bucket and it was handling "listen to" requests as well.

These days are over now but in order to make the whole thing more efficient, I would like to "forward" a file-upload to the microservice I am working on.

There is simply no need to store this file locally, it does not even have to reside in the working memory as whole. Hence, the request could be forwarded directly to the other service. Please note: I cannot simply upload the file to my micrososervice. It's independent and does not know anything about permissions and ownership.

So, instread of something like this:

@RequestMapping(value = "/tracks", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public @ResponseBody
Track uploadTrack(
        @RequestPart("audioFile") MultipartFile audioFile,
        @RequestPart("name") String name
) {
    return this.trackService.storeTrack(name, audioFile);
}

I would like to have something like:

@RequestMapping(value = "/tracks", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public @ResponseBody
Track uploadTrack(ByteStream entireHttpRequest) {
    return this.microserviceClient.createTrack(entireHttpRequest);
}
Stefan Falk
  • 21,778
  • 41
  • 170
  • 332
  • You will have to disable spring's multipart handling and handle the input stream yourself (read bytes into a buffer and write to the remote service until the input stream is consumed). See this question: https://stackoverflow.com/questions/37870989 – armandino Jan 24 '22 at 22:08

0 Answers0