There is a field in the database table that receives images in blob format. How can this be displayed on the site? The main goal is to send images to the database, and display them in the website.It would be great if you gave an example of the go code
this is insert data code:
ins, err := db.Query(fmt.Sprintf("INSERT INTO `photo` (`photo`)" +" VALUES('%s')", img))
if err != nil {
panic(err)
}
defer ins.Close()
attempt to display an image(saving in a variable):
vars := mux.Vars(r)
res, err := db.Query(fmt.Sprintf("SELECT * FROM `photo` WHERE `id` = '%s'", vars["id"]))
if err != nil {
panic(err)
}
showPhoto = Photo{}
for res.Next() {
var post Photo
err = res.Scan(&post.Id, &post.Img)
if err != nil {
panic(err)
}
encodeImg, err := b64.StdEncoding.DecodeString(post.Img)
showPhoto = post
}
several files are sent from one input, so the terminal displays the error " 1 variable, but in base64.stdencoding.decodeString returns 2 values"
question from:
https://stackoverflow.com/questions/65641598/how-can-i-save-images-in-the-database-and-display-them-on-the-site 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…