Commit b1620a23 by 李嘉林

头像上传换移动云

parent cd8246ad
...@@ -346,41 +346,38 @@ export default { ...@@ -346,41 +346,38 @@ export default {
wx.showLoading({ wx.showLoading({
title: '上传中...', title: '上传中...',
}) })
this.get_oss_config(()=>{ wx.uploadFile({
let fileName = `${_this.ossConfig.dir}${userImg.split("/").pop()}`; url: `${process.env.OLSHOP_URL}/common/uploadFile`,
console.log(fileName,'----------fileName') filePath: userImg,
wx.uploadFile({ name: "file",
url: `${_this.ossConfig.host}`, formData: {},
filePath: userImg, success(res) {
name: "file", console.log(res.data, '--res')
formData: { try {
key: fileName, let data = res.data ? JSON.parse(res.data) : {};
OSSAccessKeyId: _this.ossConfig.accessid, if (data.code == 200) {
policy: _this.ossConfig.policy, _this.userMsg.headPortraitUrl = data.data.imgUrl;
signature: _this.ossConfig.signature,
success_action_status: "200",
},
success(res) {
if (res.statusCode == 200) {
let host =
_this.ossConfig.host.substr(-1) == "/"
? _this.ossConfig.host
: `${_this.ossConfig.host}/`;
_this.userMsg.headPortraitUrl = `${host}${fileName}`;
console.log(_this.userMsg.headPortraitUrl,'---_this.userMsg.headPortraitUrl') console.log(_this.userMsg.headPortraitUrl,'---_this.userMsg.headPortraitUrl')
wx.hideLoading(); wx.hideLoading();
} }
//do something } catch (error) {
},
fail(res) {
console.log(res, "-----------------fail");
wx.showToast({ wx.showToast({
title: "上传失败", title: "上传失败",
icon: "error", icon: "error",
duration: 1000, duration: 1000,
}); });
}, }
}); //do something
},
fail(res) {
log.info(res,'---上传头像失败')
console.log(res,'---上传头像失败')
wx.showToast({
title: "上传失败",
icon: "error",
duration: 1000,
});
},
}); });
}, },
random_string(len) { random_string(len) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment