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" "strconv" ) 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"] val := form.Value["scene"] scene := val[0] if len(scene) < 1 { scene = "other" } datasetId, _ := strconv.ParseInt(form.Value["datasetId"][0], 10, 64) req = proto.UploadFileRequest{ Creator: userInfo.UserId, Scene: scene, Files: files, DatasetId: datasetId, } data, err = repo.UploadFile(c, req) go s.SaveLog("文件上传", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return }