HTML <span> <a class="file" onclick="uploadimg()">选择图片</a> </span> JS function uploadimg(me) { wxshop.wx_config(function() { wx.chooseImage({ count: 9, //设置一次能选择的图片的数量 sizeType: ['original', 'compressed'], //指定是原图还是压缩,默认二者都有 sourceType: ['album','camera'], //可以指定来源是相册还是相机,默认二者都有 success: function(res) { //微信返回了一个资源对象 //res.localIds 是一个数组 保存了用户一次性选择的所有图片的信息imgid = res.localIds;
//把图片的路径保存在images[localId]中--图片本地的id信息,用于上传图片到微信浏览器时使用 ulLoadToWechat(me); //把这些图片上传到微信服务器 一张一张的上传 } }); }); }
function ulLoadToWechat(me) { wxshop.wx_config(function() { if (!imgid.length) { alert('图片上传成功!'); } else { var localId = imgid.pop(); wx.uploadImage({ localId: localId, success: function(res) { wxImgDown(res.serverId, me);//将图片路径存在了本地数据库 ulLoadToWechat(); }, fail: function(res) { alert(JSON.stringify(res)); } }); } }); };
上传多张图片到微信服务器
猜你喜欢
转载自www.cnblogs.com/3b2414/p/9494163.html
今日推荐
周排行