简体   繁体   中英

convert URL into file object using javascript only

Link given:

example.com/data/videos/videoname.mp4

How to pass this link as fileInput?

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

All should be done in javascript only. Need a solution in pure javascript only not using any jquery.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM