methods:{
//七牛云base64上传
base64(pic){
var than = this;
//pic base64字符串
this.getQiniuToken({}).then((res)=>{
if(res.code==0){
var token = res.data;
pic = pic.replace(/^.*?,/,'');
var url = "http://upload.qiniu.com/putb64/"+this.fileSize(pic)+"/"+window.btoa("0612_"+ new Date().getTime()+"_"+parseInt(Math.random()*10)); //非华东空间需要根
var xhr = new XMLHttpRequest();
xhr.onreadystatechange=function(){
if (xhr.readyState==4){
//上传成功返回的数据
var res = JSON.parse(xhr.responseText);
console.log(res );
}
}
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/octet-stream");
//此处UpToken 后面带空格
xhr.setRequestHeader("Authorization", "UpToken "+token);
xhr.send(pic);
}
});
},
fileSize(str){
if (str.indexOf('=') > 0) {
var indexOf = str.indexOf('=');
str = str.substring(0,indexOf);
}
return parseInt(str.length - (str.length / 8) * 2)
},
}
image.png
网友评论