本人node小白,最新在學(xué)習(xí)blob方面的知識(shí)?,F(xiàn)在需要從服務(wù)器把圖片的二進(jìn)制數(shù)據(jù)傳到頁(yè)面中,該如何做,請(qǐng)看我寫的代碼服務(wù)端:前端:請(qǐng)問服務(wù)端生成圖片二進(jìn)制數(shù)據(jù)的代碼該如何寫?
3 回答
已采納

名分開就是姓名
TA貢獻(xiàn)39條經(jīng)驗(yàn) 獲得超4個(gè)贊
var xhr = new XMLHttpRequest(); ? ?
xhr.open("get", "xxx.jpg", true);
xhr.responseType = "blob";
xhr.onload = function() {
? ?if (this.status == 200) {
? ? ? ?var blob = this.response; ?// this.response也就是請(qǐng)求的返回就是Blob對(duì)象
? ? ? ?var img = document.createElement("img");
? ? ? ?img.onload = function(e) {
? ? ? ? ?window.URL.revokeObjectURL(img.src); // 清除釋放
? ? ? ?}; ? ? ? ?img.src = window.URL.createObjectURL(blob);
? ? ? ?eleAppend.appendChild(img); ? ?
? ?}
}
xhr.send();
- 3 回答
- 0 關(guān)注
- 2690 瀏覽
添加回答
舉報(bào)
0/150
提交
取消