···javascript
function (base64) {
self.editor.focus()
console.log(base64)
let base = window.atob(base64.replace(/^.*?,/, ''))
console.log(base)
getOssSts().then(response => {
let client = new OSS.Wrapper({
accessKeyId: response.data.AccessKeyId,
accessKeySecret: response.data.AccessKeySecret,
stsToken: response.data.SecurityToken,
endpoint: process.env.ENDPOINT,
bucket: process.env.BUCKET
})
client.put(self.objectKey, new Buffer(base)).then(function (result) {
self.onUploadSuccess(result.res)
console.log(result)
}).catch(function (err) {
console.log(err)
})
console.log(response)
})
})
https://yq.aliyun.com/articles/253170?spm=5176.100240.searchblog.9.8tMWIb 参考这篇文章
// Convert a base-64 string to a byte array
base64ToBytes (base64) {
// Use browser-native function if it exists
if (typeof atob === 'function') return this.stringToBytes(window.atob(base64))
// Remove non-base-64 characters
base64 = base64.replace(/[^A-Z0-9+/]/ig, '')
var bytes = []
for (var i = 0; i < base64.length; i++) {
switch (i % 4) {
case 1:
bytes.push((base64map.indexOf(base64.charAt(i - 1)) << 2) |
(base64map.indexOf(base64.charAt(i)) >>> 4))
break
case 2:
bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & 0xF) << 4) |
(base64map.indexOf(base64.charAt(i)) >>> 2))
break
case 3:
bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & 0x3) << 6) |
(base64map.indexOf(base64.charAt(i))))
break
}
}
return bytes
},
stringToBytes (str) {
var bytes = []
for (var i = 0; i < str.length; i++) {
bytes.push(str.charCodeAt(i))
}
return bytes
}
一定要转成base64ToBytes
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。