'''chooseImage(type) {
var that = this;
uni.chooseImage({
count: 1, //默认9
sizeType: ['orginial', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: res => {
var path = res.tempFilePaths[0];
this.$request.getSTS().then(res => {
var accessid = res.data.data.accessKeyId;
var accesskey = res.data.data.accessKeySecret;
var securityToken = res.data.data.securityToken;
var expiration = res.data.data.expiration;
console.log('上传');
var uploadFileSize = 1024 1024 100; // 上传文件的大小限制100m
var policyText = {
expiration: expiration, //设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了
conditions: [
['content-length-range', 0, uploadFileSize] // 设置上传文件的大小限制
]
};
var osshost = 'http://rongwodev.oss-cn-shanghai.aliyuncs.com';
var policyBase64 = Base64.encode(JSON.stringify(policyText));
var message = policyBase64;
var bytes = Crypto.HMAC(Crypto.SHA1, message, accesskey, {
asBytes: true
});
var signature = Crypto.util.bytesToBase64(bytes);
var timetamp = new Date().getTime();
that.imageSrc = path;
let pos = that.imageSrc.lastIndexOf('.');
console.log(this.imageSrc);
let filename = that.imageSrc.substring(0, pos); // 文件名
let extendName = that.imageSrc.substring(pos + 1); // 扩展名
// 文件路径
let stroeAs = 'rongwodev/' + timetamp + this.random_string(2) + '.' + extendName;
console.log('通');
console.log(osshost);
console.log(that.imageSrc);
console.log(accessid);
console.log(securityToken);
uni.uploadFile({
url: osshost,
filePath: that.imageSrc,
fileType: 'image',
name: 'file',
formData: {
key: stroeAs,
policy: policyBase64,
OSSAccessKeyId: accessid,
'x-oss-security-token': securityToken,
success_action_status: '200', //让服务端返回200,不然,默认会返回204
signature: signature
},
success(res) {
console.log(res);
uni.showToast({
title: '上传成功',
icon: 'success',
duration: 1000
});
if (type === "logo") {
console.log(osshost + '/' + stroeAs);
that.logo = osshost + '/' + stroeAs;
} else {
that.businessLicense = osshost + '/' + stroeAs;
}
},
fail: res => {
console.log(res);
}
});
});
}
});
}, '''
4***@qq.com (作者)
这个可以解决,你们官方说的 : 先把 btoa 的代码注释掉 参考https://ask.dcloud.net.cn/question/77248
2020-08-18 16:37