package v1 import ( "fmt" "github.com/gin-gonic/gin" "net/http" "property-applete-gateway/errors" "property-applete-gateway/utils" param_v1 "property-applete-gateway/param/v1" "git.getensh.com/common/gopkgs/tasker/httptasker" ) // UploadFile godoc // @Summary 上传文件 // @Description 上传文件 // @Tags upload // @Accept json // @Produce json // @Param token header string true "jwt token" // @Param file formData file false "file" // @Success 200 {object} v1.UploadResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/upload [post] func (c Controller) Upload(ctx *gin.Context) { // 解析参数 parseParamTask := func() error { file, err := ctx.FormFile("file") if err != nil { fmt.Printf("upload get file:%v\n", err) return errors.SystemError } imgMime := file.Header.Get("Content-Type") dst := file.Filename f, err := file.Open() if err != nil { fmt.Printf("upload file open error:%v\n", err) return err } defer f.Close() url, err := utils.UploadToMinio(dst, f, file.Size, imgMime) if err != nil { fmt.Printf("upload to minio error:%v\n", err) return err } // 响应数据 resp := ¶m_v1.UploadResponse{} resp.Data = url ctx.JSON(http.StatusOK, resp) return nil } httptasker.Exec(ctx, parseParamTask) }