小编给大家分享一下微信小程序实现上传照片代码的案例分析,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

纸上谈坑
在我实现了这个功能之前,我讲讲我是怎么在这个坑里爬上来的:
我实现上传文件后端的接口的参数是String类型的
前台传的参数:/tupian/20230522/404.html 1. MultipartFile 2.base64
微信上传文件的开发文档
小程序代码
<!-- index.wxml -->
<view>
<view>文件上传</view>
<view>
<input id="file" type="file" bindtap="uploader"></input>
</view>
</view>
// index.js
Page({
data: {
},
uploader: function () {
wx.chooseImage({
count: 1,
success: function(res) {
let imgPath = res.tempFilePaths[0]
wx.uploadFile({
url: 'http://localhost:8080/customerRegister/uploadPricture',
filePath: imgPath,
name: 'files',
success:res=>{
console.log(res)
}
})
}
})
},
})