小程序图片上传

wxml部分:

<view class='tupian'>
<image bindtap="chooseimage" style='width:33.33%;height:73px;' src="../../images/tupian.png" hidden='{{hiddentupian}}'/>
<block wx:for="{{tempFilePaths}}" wx:key="{{index}}" >
<image src="{{tempFilePaths[index]}}" mode="aspecFill" style='width:33.33%;height:73px;float:right' />
</block>
</view>

js部分:

chooseimage: function () {
var that = this;
wx.chooseImage({
count: 3, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
that.setData({
tempFilePaths: res.tempFilePaths,
hiddentupian:true,
})
}
})
},

submit部分:

wx.uploadFile({
url: url + '/fabu/fabu!upload.action', //仅为示例,非真实的接口地址
method: 'post',
filePath: tpsc[i],
name: 'file',
formData: {
'filen': result11[i],
},
header: {
"Content-Type": "multipart/form-data"
},
success: function (res) {
var data = res.data
}
})

猜你喜欢

转载自www.cnblogs.com/zcy1995/p/9361391.html