<view>上传图片</view> <view> <view> <button bindtap="getImg">上传图片</button> </view> <view wx:for="{{imgSrc}}" wx:key="{{index}}"> <image mode="aspectFit" src="{{item}}" /> </view> </view>
page({ data:{ imgSrc:[] }, getImg(e){ var _this = this; wx.chooseImage({ count:9,//照片可选数量 sizeType:['original','compressed'],//原图,缩略图 sourceType:['album','camera'],//相册,相机 success:function(res){ var tempFilePaths = res.tempFilePaths console.log(tempFilePaths) _this.setData({ imgSrc:[..._this.data.imgSrc,...tempFilePaths] }) } }) }, })
移动端上传照片时,需要在在wx.upload请求时,添加header:{
"Content-Type": "multipart/form-data"
},
否则,可能传给后天的数据是application/octet-stream