小程序之图片上传

//调用相册等选择图片,得到图片的相对路劲
up_img: function () { var that = this; wx.chooseImage({ count: 1, // 默认9 sizeType: ['compressed'], sourceType: ['album', 'camera'], success: function (res) { var tempFilePaths = res.tempFilePaths; upload(that, tempFilePaths); } }) }
//把图片上传到服务器
function
upload(page, path) { wx.showToast({ icon: "loading", title: "正在上传" }), wx.uploadFile({ url: app.globalData.url + 'index.php?g=api&m=api&a=img_upload_api', filePath: path[0], name: 'file', formData: { openid: wx.getStorageSync('openid'), is_type: 1 }, success: function (res) { if (res.statusCode != 200) { wx.showModal({ title: '提示', content: '上传失败', showCancel: false }) return; } var res_data = JSON.parse(res.data); // poster_src = res_data.data; page.setData({ poster_src: res_data.data }); }, fail: function (e) { console.log(e); wx.showModal({ title: '提示', content: '上传失败', showCancel: false }) }, complete: function () { wx.hideToast(); //隐藏Toast } }); }

猜你喜欢

转载自www.cnblogs.com/wanan-01/p/9057480.html
今日推荐