1

I'm doing a project of mine something like lets say youtube I've done the uploading videos part but I'm stuck on how can I playback those videos to Postman?

I've tried making the return type MultipartFile class and just returning the file but it doesn't seems to work.

@RestController
public class VideoController {
    @PostMapping(value = "/upload")
    public void uploadVideo(@RequestParam("video") MultipartFile file) throws IOException {

        byte[] bytes = file.getBytes();
        File newVideo = new File("D:\\test\\" + file.getName() + ".mp4");
        FileOutputStream fos = new FileOutputStream(newVideo);
        fos.write(bytes);
    }
}
Uponn
  • 199
  • 2
  • 3
  • 15
  • 5
    By Postman you mean this https://www.getpostman.com/? Why do you think it can play videos? – NeplatnyUdaj May 02 '19 at 15:03
  • @NeplatnyUdaj can't it? I've returned images so I though it could do the same with videos. – Uponn May 02 '19 at 15:09
  • `If your API endpoint returns an image, Postman will detect and render it automatically.`. Not a word about videos. https://learning.getpostman.com/docs/postman/sending_api_requests/responses/#preview – NeplatnyUdaj May 02 '19 at 15:21

1 Answers1

1

I don't think Postman support video streaming. Regardless, in order to stream video your VideoController would need to have a GetMapping method that supports range requests which is a non-trivial coding task.

You should take a look at the community project Spring Content. This project is an abstraction over Storage and provides a range of Storage implementations including the good old Filesystem. Importantly, it also supports video streaming out of the box as this post describes.

NB: Current version of Spring Content is 0.8.0.

Community
  • 1
  • 1
Paul Warren
  • 2,411
  • 1
  • 15
  • 22