后端blob 怎么显示在页面_将数据库保存的blob图片流传到前端显示出来

list[i].bookCover = "data:image/png;base64," +list[i].bookCover;

console.log(list[i].bookCover) ;

}

if(list==null){

var toastText="获取数据失败"+res.data.strMsg;

wx.showToast({

title: toastText,

icon:'',

duration:6000

});

} else {

that.setData({

list:list

})

}

}

})

wxml:

src="{{item.bookCover}}" class="card-left">

{{item.bookDesc}}

后端实现:

try {

InputStream inputStream = blob.getBinaryStream();

ByteArrayOutputStream output = new ByteArrayOutputStream();

byte[] buffer = new byte[100];

int n = 0;

while (-1 != (n = inputStream.read(buffer))) {

output.write(buffer, 0, n);

}

Base64.Encoder encoder = Base64.getEncoder();

result=encoder.encodeToString(output.toByteArray());

output.close();

} catch (SQLException | IOException e) {

e.printStackTrace();

}

你可能感兴趣的:(后端blob,怎么显示在页面)