I want the user to be able to upload a video and then, by clicking a button, load the video into a tag to view.
Here is an example:
HTML:
function loadvideo() { video = document.getElementById('videoinput').files[0]; videoelement = document.getElementById('videopreview'); videoelement.src = video; ///I don't think this will work as we need to read the file first?? }
<html> <body> <input type="file" accept="mp4" id="videoinput"> <video id="videopreview"> <button onclick="loadvideo()">Load The Video</button> <script type="javascript src="myscript.js"> </body> </html>
2
Answers
Preview video before upload
If you want to preview a video file before actually uploading it, you could send the Input’s Event.target.files[0] into URL.createObjectURL to a newly created
<video>
element’ssrc
attribute.To then insert such VideoElement into a designated preview wrapper, you can use Element.replaceChildren()