本文实例为大家分享了js使用base64格式上传文件的具体代码,供大家参考,具体内容如下 html页面 <input type="file" id="fielinput" /&
本文实例为大家分享了js使用base64格式上传文件的具体代码,供大家参考,具体内容如下
html页面
<input type="file" id="fielinput" />
<img id="txshow" style="width:100px;height:100px;"/>
<br/>解析之后的base64数据:<br/>
<p id="data"></p>
js部分
var input = document.getElementById("fielinput");
input.addEventListener('change', readFile, false);
function readFile() {
var file = this.files[0];
//判断是否是图片类型
var reader = new FileReader(); // 返回一个新的FileReader函数
reader.readAsDataURL(file);
reader.onloadstart = function (e){
console.log(e)
console.log('开始了')
}
reader.onprogress = function(e){
console.log(e)
}
reader.onload = function (e) {
console.log(e);
console.log(reader.result);
txshow.src = this.result;
document.getElementById("data").innerText=this.result.substring(this.result.indexOf(',')+1);
}
reader.onloadend = function(e){
console.log(e)
console.log('结束了')
}
}
小提示
function fileFORMData(files){
console.log(this.files[0])
console.log(files.target.files[0])
}
在上传文件中,this.files[0]
全等于files.target.files[0]
的
--结束END--
本文标题: JS使用base64格式上传文件
本文链接: https://www.lsjlt.com/news/164271.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0