微信小程序 图片上传
获得page数据
this.data.data字段
设置page数据
this.setData({
data字段: 设置的值
})
上传文件 wx.uploadFile
注意:在微信公众平台上设置域名,否则域名访问无效
wx.uploadFile({
filePath: that.data.imageScr,
// 文件key名称
name: 'img',
url: 'https://域名',
formData: {
// 附加信息
'content': that.data.posterContent
},
header: {
"Content-Type": "multipart/form-data"
},
success (res){
that.setData({
hasGenerateImageSrc: true,
generateImageScr: "https://域名/" + res.data
})
},
fail: function (res) {
wx.hideToast();
wx.showModal({
title: '错误提示',
content: '上传图片失败',
showCancel: false,
success: function (res) { }
})
}
})
}
wx.uploadFile 查看完整的失败信息
complete(res){
console.log(res)
}