美文网首页
检测url是图片还是视频,或者不合法

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

作者: 不会写代码的机器人 | 来源:发表于2021-09-18 16:31 被阅读0次

    利用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是图片还是视频,或者不合法

          本文链接:https://www.haomeiwen.com/subject/exkygltx.html