base64上传七云获取key
上传到七云牛 base64 转化为 key(原生的ajax)
putb64 = async () => { let picBase = base64图片; picBase = picBase.substring(23);
function fileSize(str) { let fileSize, indexOf = str.indexOf('='); if (indexOf > 0) { str = str.substring(0, indexOf); } fileSize = parseInt(str.length - (str.length / 8) * 2); return fileSize; }
const url = `https://upload-z2.qiniup.com/putb64/${fileSize(picBase)}`; const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { let keyText = xhr.responseText; console.log(keyText); } }; xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type", "application/octet-stream"); xhr.setRequestHeader("Authorization", `UpToken ${this.state.uptoken}`); xhr.send(picBase); };
|