javascript 生成blob url的方法

javascript 生成blob url的方法

<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <title>Blob Url</title>
</head>
<body>
    <video  width="400" controls="controls"></video>
    <script type="text/javascript">
        //创建XMLHttpRequest对象
        var xhr = new XMLHttpRequest();
        //配置请求方式、请求地址以及是否同步
        xhr.open('POST', '/sfwanshengjie/mp4/shipin1.mp4', true);
        //设置请求结果类型为blob
        xhr.responseType = 'blob';
        //请求成功回调函数
        xhr.onload = function(e) {
            if (this.status == 200) {
                //获取blob对象
                var blob = this.response;
                console.log(blob);
                //获取blob对象地址,并把值赋给容器
                document.getElementById("video").src = URL.createObjectURL(blob);
            }
        };
        xhr.send();
    </script>
</body>
</html>