给七牛云上传文件并返回访问地址


<template>
<a-upload name="file"
:supportServerRender="true"
:multiple="true"
action="https://up-z2.qiniup.com/"
:headers="headers"
:data="formData"
:beforeUpload="beforeUpload"
:disabled = "allowUpload"
:fileList="fileList"
:remove="handleRemove"
@change="handleChange">
<a-button>
<a-icon type="upload" /> 选择上传的文件
</a-button>
</a-upload>
</template>

<script>
export default {
name: "",
props:{
communityDID :{
type:Number|String,
default:''
},
token:{
type:String,
default:''
}
},
data(){
return{
allowUpload:false,
formData:{
token:'',
key:''
},
headers: {
authorization: 'authorization-text',
},
fileList:[],
addFile:{}
}
},
methods:{
handleRemove(file) {
this.fileList = [];
},
beforeUpload(info){
this.fileList = [...this.fileList, info];
this.formData.key = this.communityDID + '-' +(new Date()).getTime() + '-' + info.name;
this.formData.token = this.token;
this.addFile.name = info.name;
this.addFile.communityDID = this.communityDID;
this.addFile.url = this.formData.key;
},
handleChange(info) {
let fileList = [...info.fileList];
fileList = fileList.slice(-2);
fileList = fileList.map(file => {
if (file.response) {

file.url = file.response.url;
console.log('上传成功','http://q1rhut7gn.bkt.clouddn.com'+file.response.key)
this.$emit('fileUrlMethod',this.addFile)
}
return file;
});
this.fileList = fileList;

},
},
mounted(){

}
}
</script>

<style scoped>

</style>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM