Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Download video file:
- http://www.filedropper.com/backup_11
- Call:
- serve(response, Paths.get("/path/to/" + "backup" + ".mp4").toFile());
- Method:
- public static void serve(HttpServletResponse response, File file) throws IOException {
- response.setContentType("application/octet-stream");
- // response.setHeader ("Content-Disposition", "attachment;filename=filename.mp4");
- response.setHeader("Content-Type", "video/mp4");
- int BUFFER_SIZE = 512;
- try (
- BufferedInputStream input = new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE);
- BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream(), BUFFER_SIZE);
- ) {
- byte[] bytes = new byte[BUFFER_SIZE];
- int length;
- while ((length = input.read(bytes)) > 0) {
- output.write(bytes, 0, length);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement