在用weui,图片用了base64做为预览,这个时候可以将base64上传到七牛返回URL吗
let Base64 = require('js-base64').Base64;
cut () {
this.$refs.cropper.getCropData((data) => {
let uuid = this.uuid()
let pic = data.replace(/^.*?,/, '')
http.request({
method: 'POST',
url: "http://upload.qiniu.com/putb64/-1/key/"+Base64.encode(uuid+'.'+this.file_type),
headers: {'Content-Type': 'application/octet-stream', 'Authorization': "UpToken "+this.qiniu_token}
}).then(response => {
this.$emit("getCover", response.data.key);
}).catch(function (error) {
console.log('上传失败')
});
})
},
uuid() {
let s = [];
let hexDigits = "0123456789abcdef";
for (let i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4";
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
s[8] = s[13] = s[18] = s[23] = "-";
return s.join("");
}
返回的数据
{hash: "Fto5o-5ea0sNMlW_75VgGJCv2AcJ", key: "fa2750a4-dac9-499a-ab25-bac7eec37ffc.jpg"}
url参数 -1 是忽略大小, key 是返回自定义参数使用,
这是我项目里的代码,因为是部分代码,有的参数就自己脑补吧!
参见官方文档
https://support.qiniu.com/hc/...