element upload长传base64文件,readAsD
作者:
zjm_b5fe | 来源:发表于
2021-03-05 14:50 被阅读0次 <Upload
class="upload-demo"
action=""
:http-request="uploadHandler"
:show-file-list="false"
:beforeUpload="beforeUpload"
accept=".zip"
>
<Button size="small" plain icon="el-icon-upload2">
选择文件
</Button>
<div slot="tip" class="el-upload__tip">
只能上传zip包,且不超过500kb
</div>
</Upload>
uploadHandler(params) {
const reader = new FileReader()
// reader.readAsArrayBuffer(params.file) // 大文件有问题
reader.readAsDataURL(params.file)
reader.onload = (e) => {
let result = e.target.result.match(/.*;base64\,(.*)/)[1] // base64 内容
// debugger
// e.target.result ArrayBuffer
// ArrayBuffer 转成base64
// const base64String = window.btoa(String.fromCharCode(...new Uint8Array(e.target.result)))
}
},
本文标题:element upload长传base64文件,readAsD
本文链接:https://www.haomeiwen.com/subject/rxwrqltx.html
网友评论