The upload component of element is used here. For related upload hooks, please see the official website.
1. Obtain the signature data related to the oss background
It is recommended to obtain it through the interface
2. Upload
//获取oss相关参数
// getOsstoken
async beforeUploadMasterImg(file) {
console.log("点击上传");
await this.getOssSingnature(file);
},
async getOssSingnature(file) {
var _this = this;
console.log("开始准备上传");
await getOsstoken({ dir: "xxx/xxx/xx/" }).then((res) => {
console.log("获取上传地址");
console.log(res);
_this.pageUpObj.policy = res.data.policy;
_this.pageUpObj.dir = res.data.dir + "xxx";//oss存储文件夹
_this.pageUpObj.OSSAccessKeyId = res.data.accessId;
_this.pageUpObj.host = res.data.host;
_this.pageUpObj.key = res.data.dir + file.uid + "_" + file.name; //文件命名唯一值 后续url拼接使用
_this.pageUpObj.signature = res.data.signature;
});
},
uploadSuccess() {
console.log('上传成功获得url');
const MSGurl = this.pageUpObj.host + "/" + this.pageUpObj.key;
},
20230816--Fix download failure function
Reason: The host address does not include https and needs to be manually set to https://
_this.pageUpObj.host ='https://'+ res.data.host.split('//')[1];