-
Notifications
You must be signed in to change notification settings - Fork 3
/
attachment.go
34 lines (30 loc) · 1.03 KB
/
attachment.go
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
package backend
import (
"github.com/MQEnergy/go-skeleton/internal/app/controller"
"github.com/MQEnergy/go-skeleton/internal/request/attachment"
"github.com/MQEnergy/go-skeleton/internal/vars"
"github.com/MQEnergy/go-skeleton/pkg/response"
"github.com/MQEnergy/go-skeleton/pkg/upload"
"github.com/gofiber/fiber/v2"
)
type AttachmentController struct {
controller.Controller
}
var Attachment = &AttachmentController{}
// Upload 上传资源
func (c *AttachmentController) Upload(ctx *fiber.Ctx) error {
reqParams := &attachment.UploadReq{}
if err := c.Validate(ctx, reqParams); err != nil {
return response.BadRequestException(ctx, err.Error())
}
fileName, err := ctx.FormFile("file")
if err != nil {
return response.BadRequestException(ctx, err.Error())
}
reqParams.FileName = fileName
fileHeader, err := upload.New(0, []string{}).UploadToLocal(&vars.Config, reqParams.FileName, reqParams.FilePath)
if err != nil {
return response.BadRequestException(ctx, err.Error())
}
return response.SuccessJSON(ctx, "", fileHeader)
}