123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "github.com/gin-gonic/gin"
- "github.com/jaryhe/gopkgs/tasker/httptasker"
- "net/http"
- "smart-enterprise-management-gateway/errors"
- param_v1 "smart-enterprise-management-gateway/param/v1"
- "smart-enterprise-management-gateway/utils"
- )
- // UploadFile godoc
- // @Summary 上传文件
- // @Description 上传文件
- // @Tags upload,v1.0
- // @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.0/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)
- }
|