feat:完善项目
This commit is contained in:
64
app/api/upload.go
Normal file
64
app/api/upload.go
Normal file
@ -0,0 +1,64 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ArmedPolice/config"
|
||||
"ArmedPolice/lib"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Upload struct{}
|
||||
|
||||
/**
|
||||
* @apiDefine Upload 上传管理
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {post} /api/upload 上传接口
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName Upload
|
||||
* @apiGroup Upload
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {File} file 文件信息
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Object} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.url 文件访问地址
|
||||
* @apiSuccess (200) {String} data.filepath 文件地址
|
||||
* @apiSuccess (200) {String} data.filename 文件名称
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data":{
|
||||
* "url": "http://192.168.99.185:8010/upload/20210401/ad228811386cb8cd089a9d668d2885cd.png",
|
||||
* "filepath": "/upload/20210401/ad228811386cb8cd089a9d668d2885cd.png",
|
||||
* "filename": "8251863448d7ed13393bf0aae2211272.jpg"
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
func (a *Upload) Upload(c *gin.Context) {
|
||||
file, err := c.FormFile("file")
|
||||
|
||||
if err != nil {
|
||||
APIFailure(err)(c)
|
||||
return
|
||||
}
|
||||
resp := new(lib.UploadHandle)
|
||||
|
||||
if resp, err = lib.Upload(config.SettingInfo.Upload.Path, config.SettingInfo.Upload.Exts, config.SettingInfo.Upload.Size,
|
||||
config.SettingInfo.Upload.Rename).Handle()(file, config.SettingInfo.Domain); err != nil {
|
||||
APIFailure(err)(c)
|
||||
return
|
||||
}
|
||||
if err = c.SaveUploadedFile(file, resp.RelativePath); err != nil {
|
||||
APIFailure(err)(c)
|
||||
return
|
||||
}
|
||||
APISuccess(resp)(c)
|
||||
}
|
Reference in New Issue
Block a user