<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