<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<ul>
<li>
上传视频:<input type="file" class="video">
</li>
</ul>
<button>Send</button>
<script>
let params = new FormData();
$('.video').on('change', function( e ){
//e.currentTarget.files 是一个数组,如果支持多个文件,则需要遍历
params.append('filesrc', e.currentTarget.files[0])
var reader = new FileReader()
reader.readAsDataURL( e.currentTarget.files[0])
// 获取base64
reader.onload = function() {
console.log('输出base64',reader.result)
}
});
</script>
</body>
</html>