当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JS 根据文件URL读取其文件 内容并显示

JS 根据文件URL读取其文件 内容并显示

2020年07月14日  | 移动技术网IT编程  | 我要评论
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //url转blob
    function urlToBlob() {
      let file_url =
        'http://obdataplatform-test.oss-cn-shenzhen.aliyuncs.com/2020_07_10/391f56b9-f4bc-408b-868b-31ea0f8b1b47.hex'
      let xhr = new XMLHttpRequest();
      xhr.open("get", file_url, true);
      xhr.responseType = "blob";
      xhr.onload = function () {
        if (this.status == 200) {
          // if (callback) {
          // callback();
          console.log(this.response)
          const reader = new FileReader()
          reader.onload = function () {
            console.log('reader.result', reader.result)
          }
          reader.readAsText(this.response);
        }
      };
      xhr.send();
    }
    urlToBlob()
  </script>
</body>

</html>

需要在阿里云里面配置跨域,get  请求

读取具体内容如下

本文地址:https://blog.csdn.net/qq_33878858/article/details/107317494

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网