录音上传
<template>
<div id="pic_upload dddd">
<div></div>
</div>
</template>
<script>
export default {
name: "ckaudio",
props: {
file: {
default: {}
}
},
data() {
return {
previewShow: false
};
},
watch: {
file: {
handler: function(val) {
console.log(val);
this.fileChanges(val);
},
deep: true
}
},
methods: {
// 文件上传后
fileChanges(file) {
// 请求七牛 token
this.axios.get("/weChat/qiniu/token").then(response => {
let token = response.data.data;
//上传七牛
this.uploading(token, file);
return;
});
},
//录音上传
uploading(token, e) {
if (e.target.files.length) {
for (let i = 0; i < e.target.files.length; i++) {
let file = e.target.files[i];
let param = new FormData(); //创建form对象
param.append("chunk", "0"); //断点传输
param.append("chunks", "1");
param.append("file", file, file.name);
param.append("token", token);
let config = {
headers: {
"Content-Type": "multipart/form-data"
}
};
let url = "https://upload-z1.qiniup.com/";
this.axios
.post(url, param, config)
.then(response => {
// if (response.statusText != "OK") {
// return;
// }
this.$emit("audiodata", response.data.key );
})
.catch(err => {
alert("上传录音错误,请重新上传");
});
}
}
}
}
};
</script>
<style lang="less" scope>
.img_preview .el-dialog__body {
padding: 0px !important;
}
.img_preview img {
width: 100%;
height: auto;
}
</style>
<label for="newlabel" class="el-button el-button--primary is-plain">上传录音</label>
<input
type="file"
id="newlabel"
@change="($event)=> {fileAudio = $event}"
:multiple="true"
/>
<ckaudio :file="fileAudio" @audiodata="audiodata"></ckaudio>
fileAudio: {},
audiodata(val) {
if (val) {
let params = {
};
this.api
.post("", params)
.then(res => {
})
.catch(err => {
console.log(err);
});
}
},
不求大富大贵,但求一生平凡