package v1
|
|
import (
|
"aps_crm/pkg/contextx"
|
"aps_crm/pkg/ecode"
|
"aps_crm/pkg/logx"
|
"encoding/base64"
|
"github.com/gin-gonic/gin"
|
"io/ioutil"
|
)
|
|
type ImageApi struct{}
|
|
// Upload
|
// @Tags Image
|
// @Summary 上传图像
|
// @Produce application/json
|
// @Success 200 {object} contextx.Response{data=response.LoginResponse} "成功"
|
// @Router /api/image/upload [post]
|
func (slf *ImageApi) Upload(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
file, _, err := c.Request.FormFile("file")
|
if err != nil {
|
ctx.Fail(ecode.UploadImageErr)
|
return
|
}
|
//filename := header.Filename
|
|
defer file.Close()
|
fileBytes, err := ioutil.ReadAll(file)
|
if err != nil {
|
ctx.Fail(ecode.UploadImageErr)
|
return
|
}
|
|
var enc = base64.StdEncoding
|
dd, e := enc.DecodeString(string(fileBytes))
|
logx.Infof("===============dd:%v", dd, e)
|
|
//local := upload.Local{StorePath: "c:/upload/local", Path: "c:/upload/local"}
|
//a, b, e := local.UploadFile(header)
|
//logx.Infof("================a:%v, b:%v, e:%v", a, b, e)
|
//logx.Infof("==================filename:%v, fileBytes:%v", filename, string(fileBytes))
|
ctx.Ok()
|
}
|