Reputation: 529
I currently doing an function which is to display the video on the jsp. I am saving the video in BLOB format. After getting the video in the byte[] format I want to show the video on the jsp. I used the <video>
but the video is not able to play.
How can I achieve this? Can anyone please suggest with a small example?
In jsp return an url :
<video id="addVideo" controls autoplay>
<source src="${videoUrl}" />
</video>
From the controller I return the Url as:
byte[] v_byte = (getting from the data base)
String videoUrl = new String(org.apache.commons.codec.binary.Base64.encodeBase64(v_byte);
model.addAttribute("videoUrl ",videoUrl );
Upvotes: 0
Views: 1916
Reputation: 2582
You can try the following code for video/mp4 video:
byte[] v_byte = (getting from the data base)
StringBuilder sb = new StringBuilder();
sb.append("data:video/mp4;base64,");
sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(v_byte, false)));
String videoUrl = sb.toString();
model.addAttribute("videoUrl",videoUrl );
Upvotes: 1