doUpload(){
let userId = localStorage.getItem('userId');
let token = localStorage.getItem('token');
const _this = this;
axios({
url: "http://xxx.xxx.xxx.xxx/internal/oss/get_token",
method: 'GET',
headers: {'w-auth-token': token}
}).then((res) => {
var client = new OSS.Wrapper({
accessKeyId: res.data.accessKeyId,
accessKeySecret: res.data.accessKeySecret,
stsToken: res.data.securityToken,
region: _this.region,
bucket: _this.bucket
});
const files = document.getElementById(_this.name);
if (files.files) {
const fileLen = document.getElementById(_this.name).files;
for (let i = 0; i < fileLen.length; i++) {
const file = fileLen[i];
var date = new Date();
let path="merchant/"+userId+"/"+date.getFullYear()+(date.getMonth()+1)+date.getDate()+date.getHours()+date.getMinutes()+date.getSeconds()+date.getMilliseconds()+ '.' + file.name.split('.').pop();
client.multipartUpload(path, file,{
progress: function* (percentage, cpt) {
// 上传进度
_this.uploadImg.percentage = percentage*100+'%';
console.log(_this.uploadImg.percentage);
}
}).then((results) => {
_this.uploadImg.url=results.url;
_this.uploadImg.name=results.name;
_this.uploadImg.status=true;
_this.show=true;
console.log(results.url);
console.log(results.name);
}).catch((err) => {
this.$Message.error('上传图片失败,请重试!');
});
}
}else{
this.uploadImg.status=true;
this.uploadImg.url=this.src;
}
});
},
目前是参考网上大神写的代码,用的分片上传,想问下各位大神如何限制只能上传图片,就是选择文件的时候只显示图片格式的,以及如何多图同时上传,并且有地方可以设置上传的图片大小
oss可以设置Content-Type(MIME)决定上传的格式 多图同时上传可以利用循环去做