后端URL 转成 blob 链接

2023-12-22 17:06:49
const getBlobUrl = (url) => {
 return new Promise((resolve, reject) => {
    const currentProtocol = window.location.protocol;
    let play_url
    if (currentProtocol == "https:") {
      play_url = url.replace("http:", "https:");
    }
    window.URL = window.URL || window.webkitURL;
    var xhr = new XMLHttpRequest();
    xhr.open("GET", play_url, true);
    xhr.responseType = "blob";
    xhr.onload = function (e) {
      if (this.status == 200) {
        var blob = this.response;
        // console.log(e,resolve);
        resolve(window.URL.createObjectURL(blob))  
      }else{
        reject(e)
      }
    };
    xhr.send();
  })
}

文章来源:https://blog.csdn.net/kilito_01/article/details/135154663
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。