package app import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" "lc-fangdaosha/global" "lc-fangdaosha/model/app" "lc-fangdaosha/model/common/response" ) type PictureApi struct { } // GetPicture 获取图片信息 func (pa *PictureApi) GetPicture(c *gin.Context) { code := c.Query("picode") 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.Fail(c) return } }