'How to create blob of a video file

I would like to create a Blob of a local video file file:///home/user/NodeJS/Projects/project1/routes/../videosTrans/Node.js tutorial for beginners - an introduction to Node.js with Express2.js.mp4

I could not understand the exact format of the Blob. I wish to create it to give it as input to the function createObjectURL(). The following does not work:

 var URL = this.window.URL || this.window.webkitURL;
       var file = new Blob(["file:///home/sanika/NodeJS/Projects/project1/routes/../videosTrans/Node.js tutorial for beginners - an introduction to Node.js with Express2.js.mp4"], "type" : "video\/mp4");
       var value = URL.createObjectURL(file);


Solution 1:[1]

Please use the second parameter of blob as object. so your code should be :

var URL = this.window.URL || this.window.webkitURL;
var file = new Blob(
    ["file:///home/sanika/NodeJS/Projects/project1/routes/../videosTrans/Node.js tutorial for beginners - an introduction to Node.js with Express2.js.mp4"],
    {"type" : "video\/mp4"});
var value = URL.createObjectURL(file);

Solution 2:[2]

you can get that by the following piece of code. JSFiddle demo link also given for testing

HTML Code

<form>
    <video></video>
    <br/>
    <input type="file" name="file" id="fileItem" onchange="onChange()" >
    <input type="submit" value="Play">
</form>

JS Code

    var URL = window.URL || window.webkitURL;
    var video = document.getElementsByTagName('video')[0];
    function onChange() {
        var fileItem = document.getElementById('fileItem');
        var files = fileItem.files;
        var file = files[0];
        var urlBlob = URL.createObjectURL(file);
        video.src = urlBlob;
        video.load();
        video.onloadeddata = function() {
            video.play();
        }
    }

Test It here

https://jsfiddle.net/9ad3nm2o/2/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 koceeng
Solution 2 xgqfrms