html 读取本地文件后使用文件二进制流上传文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 读取本地文件后使用文件二进制流上传文件相关的知识,希望对你有一定的参考价值。
fileUpload(e) {
const files = e.currentTarget.files;
_.each(files, (file) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = (e) => {
let imgBlob = e.target.result;
const formData = new FormData();
formData.append('file', imgBlob);
$.ajax({
url: this.api.uploadUrl,
type: 'post',
data: formData,
contentType: false, // 注意这里应设为false
processData: false,
cache: false
}).then((r) => {
this.images.push(r);
this.updateImages();
});
};
reader.onabort = () => {
dialog.showToast('图片上传被中断,请重新选择');
};
reader.onerror = () => {
dialog.showToast('图片读取失败,请重新选择');
};
})
},
<input type="file" multiple name="files[]" @change="fileUpload($event)">
以上是关于html 读取本地文件后使用文件二进制流上传文件的主要内容,如果未能解决你的问题,请参考以下文章