Aje*_*jey 4 base64 go
我有一个64位数据样本,可以在这样的img标签中使用 -
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==
"/>
我正在摆弄一个小的golang计划.在golang中,如何将这个静态基本64位编码数据动态转换为图像,然后将其作为响应时的图像发送.
前 -
http.HandleFunc("/getImage", imageHandler)
func image(res http.ResponseWriter, req *http.Request) {
data := "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg=="
// Data is the base64 encoded image
dec := b64.NewDecoder(b64.StdEncoding, data)
res.Header().Set("Content-Type", "image/png")
io.Copy(res, dec)
}