websocket传图片

使用websocket传送图片时,出现图片太大无法传送,解决办法:

发送时


let splitCount = val.length % 6000 == 0 ? val.length / 6000 : Math.ceil(val.length / 6000);
if(splitCount){					
	for (let i = 0; i < splitCount; i++) {
		let imgStr = val.substr(i * 6000,6000)
		this.send(this.sendParam(splitCount,i,imgStr));
	}
}else{
	this.send(this.sendParam(0,"",""));
}

接收时


let imgStrQ = [];
let url = '';
acceptMessage : function (msg){ 
	imgStrQ.push(msg[1]);
}
url = imgStrQ.join('').replace(/[\r\n]/g,"");//正则是为了去除换行和空格				

(45 Posts)