检测url是图片还是视频,或者不合法

利用ajax上传url来获取文件信息

testImgVidoe(imgurl) {
      this.$ajax.defaults.withCredentials = false; //关闭发送cookie
      return new Promise((resolve, reject) => {
        this.$ajax
          .get(imgurl, {
            responseType: 'blob',
          })
          .then(
            res => {
              this.$ajax.defaults.withCredentials = true; //开启发送cookie
              resolve(res.type.split('/')[0]); //获取文件类型  如:video 、image
            },
            error => {
              this.$ajax.defaults.withCredentials = true; //开启发送cookie
              // console.log(error);
              reject('地址不合法');
            }
          );
      });
    },

使用

this.testImgVidoe(url)
      .then(res => {
        console.log(res);
//返回文件类型
      })
      .catch(error => {
        console.log(error);
      });```

你可能感兴趣的:(检测url是图片还是视频,或者不合法)