wangpengfei
2023-07-26 e0a433e9c31594527a3bf7766c0bfb2cbbceffdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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()
}