XMLHttpRequest for Video Tag?

The HTML5 file Blob.slice() method is useful for creating a Blob object containing the data. This data is in the specified range of bytes of the source Blob. It uses XMLHttpRequest as in the below example.

Let us see an example to send and receive binary data using slice(). This example sends a text and uses the POST method to send the "file" to the server:

var val = new XMLHttpRequest();

val.open("POST", url, true);
val.onload = function (event) {
var blob = new Blob(['demo'], {type: 'text/plain'});

For video:

req.onload = function () {
   var blob_uri = URL.createObjectURL(this.response);
   myElement.appendChild(document.createElement("source")).src = blob_uri;
req.responseType = "blob";

Updated on: 29-Jan-2020


Kickstart Your Career

Get certified by completing the course

Get Started