检测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);
      });```
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容