小弟最近在作的小程序中需要上传图片作为参数,在postman中提交成功的数据如下图所示:
其中第一个photo参数选择的类型是文件而不是text,选择了一张图片上传,请问在小程序中应该怎么实现该功能,小弟想用uploadfile来实现但是发现这样photo参数不知道该怎么上传,其不能是文本地址,必须是和postman一样以文件作为photo参数的值,请问有懂的大神吗指点一下谢谢
wx.uploadFile({
url: 'http://106.52.255.115:8080/patrol/addroute', //仅为示例,非真实的接口地址
filePath: that.files[0],
name: 'file',
formData: {
"access-token": that.accessToken,
"stationId": that.stationId,
'name':that.name,
'identity':that.identity,
'content':that.content,
'result':that.result,
'patrolTime':that.time,
'weather':that.weather,
'way':that.way,
'photo':that.files[0]
},
success (res){
console.log("添加记录成功返回结果",res)
const data = res.data
},
fail (res){
console.log("添加记录失败返回结果",res)
// const data = res.data
},
complete (res){
console.log("添加记录完成返回结果",res)
// const data = res.data
}
})