//获取七牛token
qnUptoken(){
let that=this;
wx.request({
url: 'url',//获取token地址
method: "GET",
data: { },//数据
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
success: res => {
that.uploadToken = res.data.datas.uptoken
that.$apply();
that.uploadQiniu(that.images)
},
fail:res=>{
wx,showTast({
title:'网络错误,请退出重试'
})
wx.hideLoading()
}
})
}
//图片上传七牛
uploadQiniu(tempFilePaths) {
let token = this.uploadToken;
var that = this;
wx.uploadFile({
url: 'url',//上传七牛地址
name: 'file',
filePath: tempFilePaths[0],
header: {
"Content-Type": "multipart/form-data"
},
formData: {
token: token,
key:'wechat/2020-7-14/1.jpg'//指定路径和名字加这个即可
},
success: function(res) {
let data = JSON.parse(res.data)
if(res.statusCode!==200){
return
}
that.imgUrl='url/'+data.hash
that.skinDetection()
},
fail: function(res) {
console.log(res)
}
});
}
指定路径和重命名自行修改formData中的key即可
此数据赋值写法为WEPY写法,小程序的自行修改即可。