手机微信开发上传图片到服务器,微信开发之通过微信接口上传图片到本地服务器...

本文将带你了解微信开发通过微信接口上传图片到本地服务器,希望本文对大家学微信有所帮助。

1 /*{ 2      HTTP/1.1 200 OK 3    Connection:   close 4    Content-Type: image/jpeg  5      Content-disposition: attachment; filename="MEDIA_ID.jpg"   6    Date: Sun, 06 Jan 2013 10:20:18   GMT 7    Cache-Control: no-cache,   must-revalidate 8    Content-Length:   339721 9    10    Xxxx11 }12 这段代码是必须*/13 14 15 var images =   {  16         localId: [],  17           serverId: []  18     };    19     wx.chooseImage({  20                    // count: 1, //   默认921         //sizeType: ['original',   'compressed'], // 可以指定是原图还是压缩图,默认二者都有22          // sourceType: 'camera', // 可以指定来源是相册还是相机,默认二者都有23             success: function(res) {  24                 images.localId =   res.localIds;   //   返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片25                 alert('已选择 ' +   res.localIds.length + ' 张图片');  26   27                 if (images.localId.length ==   0) {  28                     alert('请先使用 chooseImage   接口选择图片');  29                     return;  30                 }  31                 var i = 0, length =   images.localId.length;  32                 images.serverId = [];  33                 function upload() {  34                     wx.uploadImage({  35                         localId:   images.localId[i],  36                         success: function(res)   {  // 返回图片的服务器端ID37                             i++;  38                             alert('已上传:' + i   + '/' + length);  39                               images.serverId.push(res.serverId);    40                               if (i < length) {    41                                   upload();  42                             }  43                         },  44                         fail: function(res)   {  45                               alert(JSON.stringify(res));    46                         }  47                     });  48                 }  49                 upload();  50             }  51           });       52 53 54

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之微信频道!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值