Convert url to file object using javascript only

Link:

example.com/data/videos/videoname.mp4

How can I pass this link as fileInput?

var fileUrl = window.URL.createObjectURL(fileInput);

      

Everything should be done in javascript only. Need a pure javascript solution without using any jquery.

+3


source to share


1 answer


You can use ajax and get blob



var url = 'http://example.com/data/videos/videoname.mp4';
var xhr = new XMLHttpRequest();
xhr.open('GET', 'blob:'+url, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
  if (this.status == 200) {
    var myObject = this.response;
  }
};
xhr.send();

      

0


source







All Articles