hpds_jkw_web/internal/handler/file.go

36 lines
1001 B
Go

package handler
import (
"fmt"
"github.com/gin-gonic/gin"
"hpds-iot-web/internal/proto"
"hpds-iot-web/internal/service"
"hpds-iot-web/model"
e "hpds-iot-web/pkg/err"
)
func (s HandlerService) UploadFile(c *gin.Context) (data interface{}, err error) {
repo := service.NewFileService(s.AppConfig, s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.UploadFileRequest
form, err := c.MultipartForm()
if err != nil {
go s.SaveLog("UploadFile", "Manage", "", "", userInfo.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
files := form.File["file"]
scene := c.GetString("scene")
if len(scene) < 1 {
scene = "other"
}
req = proto.UploadFileRequest{
Creator: userInfo.UserId,
Scene: scene,
Files: files,
}
data, err = repo.UploadFile(c, req)
go s.SaveLog("文件上传", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}