我所期待的上传(以postman为例,postman测试上传接口可用):
在uni-app使用uni-file-picker和uploadFile如下
<uni-file-picker
v-model="this.upload"
file-mediatype="image"
mode="list"
file-extname="png,jpg"
:limit="1"
@progress="progress"
@success="uploadSuccess"
@fail="uploadFail"
@select="select"
/>
</uni-forms-item>
<script>
methods: {
select(e) {
const tempFilePaths = e.tempFilePaths
const img = tempFilePaths[0]
// console.log(tempFilePaths)
console.log(img)
uni.uploadFile({
// TODO
url: urlConfig + "/img/upload",
name: "img",
// filePath: img,
file: img,
header: {
Authorization: store.state.userInfo.authorization,
"Content-Type": "multipart/form-data",
},
success: (res) => {
let data = JSON.parse(res.data)
// console.log(data.data)
this.formData.imgFilename = data.data
}
})
},
}
</script>
页面:
看到的请求过程:
这和想象的完全不一样,后端自然也无法接收,想问一下如何在uploadFile里面拿到图片对象然后上传(我是主要写后端的,可能用图片对象来描述比较符合一点)