package app import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" "lcfns/global" "lcfns/model/app" "lcfns/model/common/response" ) type PictureApi struct { } func (pa *PictureApi) GetPicture(c *gin.Context) { code := c.Query("eventCode") var dataId int err := global.Db.Select("p.data_id"). Table("event e JOIN picture p ON e.id = p.event_id"). Where("e.event_code = ?", code). Find(&dataId).Error if err != nil { logrus.Error(err) response.Fail(c) return } var picData app.PictureData err = global.Db.Select("id, data"). Model(&app.PictureData{}). Where("id = ?", dataId). Find(&picData).Error if err != nil { logrus.Error(err) response.Fail(c) return } c.Header("Content-Type", "image/jpeg;charset=UTF-8") //_, err = c.Writer.Write(picData.Data) //if err != nil { // logrus.Error(err) // response.FailWithMessage("获取失败", c) // return //} response.OkWithDetailed(picData.Data, "获取成功", c) }