微信小程序开发 批量选择上传图片 代码实例

最近在做微信开发,下面记录一下wx.chooseImagewx.uploadImage接口上传多张图片的代码实例。

JAVASCRIPT代码实例:

$(function(){
    wx.config({
	debug: false,
	appId: '<?php echo $signPackage["appId"];?>',
	timestamp: <?php echo $signPackage["timestamp"];?>,
	nonceStr: '<?php echo $signPackage["nonceStr"];?>',
	signature: '<?php echo $signPackage["signature"];?>',
	jsApiList: [
	    'checkJsApi',
	    'chooseImage',
	    'previewImage',
	    'uploadImage',
	    'downloadImage'
	]
    });
    wx.ready(function () {    
        var localIds = [];
	$(".weui_uploader_input").click(function(){
	    var that = $(this);
	    wx.chooseImage({
		count: 9,
		sourceType: ['camera', 'album'], 
		success: function (res) {
		    localIds = res.localIds;
		    syncUpload(that);		
		}
	    });
	});
	
        function syncUpload() {
            if (!localIds.length) {
                console.log('上传成功!');
            } else {
                var localId = localIds.pop();
                var select_name = that.attr('select_name');
                wx.uploadImage({
                    localId: localId,
                    success: function() {
                        syncUpload();
                    }
                });
            }
        }
    });
});

localIds 为上传图片队列。

厂家CPU内存硬盘流量价格购买链接
DigitalOcean11GB25GB-SSD1000GB/mUSD $5/m购买
腾讯云Qcloud22GB50GB-SSD购买
RamNode11GB25GB-SSD500GB/mUSD $5购买
Linode11GB25GB-SSD1000GB/mUSD $5购买
Vultr11GB25GB-SSD1000GB/mUSD $5/m购买

已发布

分类

作者:

标签

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注