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