客户端上传文件
首先从后台后去七牛云的token,这里使用node来获取token
1 | const getUploadToken = () => { |
接着再浏览器请求接口获取七牛云token,进行文件上传1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31<!--使用的vue+elementUI-->
qiniuUpload() {
this.axios.get("/api/work/getQiniuToken").then(res => {
let token = res.token;
let config = {
useCdnDomain: true,
region: qiniu.region.z1
};
let putExtra = {
fname: "",
params: {},
mimeType: null
};
let file = this.form.audio[0].raw;
let key = dayjs().format("YYYYMMDDHHmmssSSS") + ".mp3";
let observable = qiniu.upload(file, key, token, putExtra, config);
let that = this;
let observer = {
next: res => {
console.log(res);
},
error: err => {
console.log(err);
},
complete: res => {
that.submitForm(res.key);
}
};
let subscription = observable.subscribe(observer);
});
},