码迷,mamicode.com
首页 > Web开发 > 详细

小程序之图片上传

时间:2018-05-18 19:22:48      阅读:642      评论:0      收藏:0      [点我收藏+]

标签:app   服务器   img   ges   false   bsp   失败   .sh   col   

//调用相册等选择图片,得到图片的相对路劲
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 } }); }

 

小程序之图片上传

标签:app   服务器   img   ges   false   bsp   失败   .sh   col   

原文地址:https://www.cnblogs.com/wanan-01/p/9057480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!