废话不多说,直接上代码
let res = await fileupload();//请求oss验证信息接口请求方法
const { code, data } = res;
if (code == 200) {
var ossData = new FormData();
let keyValue = new Date().getTime()+file.name;
ossData.append("key", keyValue)
ossData.append("OSSAccessKeyId", data.access_key_id)
ossData.append("policy", data.policy)
ossData.append("signature", data.sign)
ossData.append("success_action_status", 201)
ossData.append("file", file.raw, file.name)
axios.post(data.url, ossData, { //data.url就是正式上传文件接口
headers: {
"Content-Type": "multipart/form-data"
}
})
.then(res => {
if (res.status == 201) { //上传成功 上传的路径就是要使用的路径
let url = data.url + "/" + keyValue;
this.loginForm.businessLicense = url;
}
})
.catch(error => {
})
.finally(()=>{
})
}