// Copyright 2019 githup.com. All rights reserved. // Use of this source code is governed by githup.com. package v1 import ( "github.com/gin-gonic/gin" "github.com/jaryhe/gopkgs/tasker/httptasker" "net/http" "smart-supplier-management-gateway/errors" param_v1 "smart-supplier-management-gateway/param/v1" "smart-supplier-management-gateway/utils" ) // UploadFile godoc // @Summary 上传文件 // @Description 上传文件 // @Tags upload // @Accept json // @Produce json // @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 { return errors.SystemError } imgMime :=file.Header.Get("Content-Type") dst := file.Filename f, err := file.Open() if err != nil { return err } defer f.Close() url, err := utils.UploadToMinio(dst, f, file.Size, imgMime) if err != nil { return err } // 响应数据 resp := ¶m_v1.UploadResponse{} resp.Data = url ctx.JSON(http.StatusOK, resp) return nil } httptasker.Exec(ctx, parseParamTask) }