2021-11-02 10:02:52 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"ArmedPolice/config"
|
|
|
|
"ArmedPolice/lib"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Upload struct{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @apiDefine Upload 上传管理
|
|
|
|
*/
|
|
|
|
/**
|
2021-11-04 15:30:10 +08:00
|
|
|
* @api {post} /api/v1/upload 上传接口
|
2021-11-02 10:02:52 +08:00
|
|
|
* @apiVersion 1.0.0
|
|
|
|
* @apiName Upload
|
|
|
|
* @apiGroup Upload
|
|
|
|
*
|
|
|
|
* @apiHeader {string} x-token token
|
|
|
|
*
|
|
|
|
* @apiParam {File} file 文件信息
|
|
|
|
*
|
|
|
|
* @apiSuccess (200) {Object} data 具体信息
|
|
|
|
* @apiSuccess (200) {Number} data.url 文件访问地址
|
|
|
|
* @apiSuccess (200) {String} data.filepath 文件地址
|
|
|
|
* @apiSuccess (200) {String} data.filename 文件名称
|
2021-11-04 16:44:42 +08:00
|
|
|
* @apiSuccess (200) {Number} code 成功响应状态码!
|
|
|
|
* @apiSuccess (200) {String} msg 成功提示
|
2021-11-02 10:02:52 +08:00
|
|
|
*
|
|
|
|
* @apiSuccessExample {json} Success response:
|
|
|
|
* HTTPS 200 OK
|
|
|
|
* {
|
|
|
|
* "code": 200
|
|
|
|
* "msg": "ok"
|
|
|
|
* "data":{
|
2021-11-04 16:44:42 +08:00
|
|
|
* "url": "http://192.168.99.185:8010/upload/20210401/ad228811386cb8cd089a9d668d2885cd.png",
|
|
|
|
* "filepath": "/upload/20210401/ad228811386cb8cd089a9d668d2885cd.png",
|
|
|
|
* "filename": "8251863448d7ed13393bf0aae2211272.jpg"
|
2021-11-02 10:02:52 +08:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*/
|
2021-11-04 16:44:42 +08:00
|
|
|
|
2021-11-02 10:02:52 +08:00
|
|
|
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)
|
|
|
|
}
|