同时支持OSS和MinIO文件上传

This commit is contained in:
macro 2020-01-01 15:30:58 +08:00
parent 97567117aa
commit 6bc6006404
2 changed files with 32 additions and 8 deletions

View File

@ -1,8 +1,8 @@
<template> 
<div>
<el-upload
action="http://macro-oss.oss-cn-shenzhen.aliyuncs.com"
:data="dataObj"
:action="useOss?ossUploadUrl:minioUploadUrl"
:data="useOss?dataObj:null"
list-type="picture-card"
:file-list="fileList"
:before-upload="beforeUpload"
@ -44,7 +44,10 @@
host: ''
},
dialogVisible: false,
dialogImageUrl:null
dialogImageUrl:null,
useOss:true, //使oss->true;使MinIO->false
ossUploadUrl:'http://macro-oss.oss-cn-shenzhen.aliyuncs.com',
minioUploadUrl:'http://localhost:8080/minio/upload',
};
},
computed: {
@ -73,6 +76,10 @@
},
beforeUpload(file) {
let _self = this;
if(!this.useOss){
//使oss
return true;
}
return new Promise((resolve, reject) => {
policy().then(response => {
_self.dataObj.policy = response.data.policy;
@ -89,7 +96,12 @@
})
},
handleUploadSuccess(res, file) {
this.fileList.push({url: file.name,url:this.dataObj.host + '/' + this.dataObj.dir + '/' + file.name});
let url = this.dataObj.host + '/' + this.dataObj.dir + '/' + file.name;
if(!this.useOss){
//使oss
url = res.data.url;
}
this.fileList.push({name: file.name,url:url});
this.emitInput(this.fileList);
},
handleExceed(files, fileList) {

View File

@ -1,8 +1,8 @@
<template> 
<div>
<el-upload
action="http://macro-oss.oss-cn-shenzhen.aliyuncs.com"
:data="dataObj"
:action="useOss?ossUploadUrl:minioUploadUrl"
:data="useOss?dataObj:null"
list-type="picture"
:multiple="false" :show-file-list="showFileList"
:file-list="fileList"
@ -62,7 +62,10 @@
host: '',
// callback:'',
},
dialogVisible: false
dialogVisible: false,
useOss:true, //使oss->true;使MinIO->false
ossUploadUrl:'http://macro-oss.oss-cn-shenzhen.aliyuncs.com',
minioUploadUrl:'http://localhost:8080/minio/upload',
};
},
methods: {
@ -77,6 +80,10 @@
},
beforeUpload(file) {
let _self = this;
if(!this.useOss){
//使oss
return true;
}
return new Promise((resolve, reject) => {
policy().then(response => {
_self.dataObj.policy = response.data.policy;
@ -96,7 +103,12 @@
handleUploadSuccess(res, file) {
this.showFileList = true;
this.fileList.pop();
this.fileList.push({name: file.name, url: this.dataObj.host + '/' + this.dataObj.dir + '/' + file.name});
let url = this.dataObj.host + '/' + this.dataObj.dir + '/' + file.name;
if(!this.useOss){
//使oss
url = res.data.url;
}
this.fileList.push({name: file.name, url: url});
this.emitInput(this.fileList[0].url);
}
}