12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package controllers
- import (
- "eta/eta_crawler/models"
- "os"
- )
- type ResourceController struct {
- BaseAuthController
- }
- // ResourceUpload 上传文件
- // @Title 上传文件
- // @Description 上传文件
- // @Param MenuId query int true "目录ID"
- // @Param File query file true "文件"
- // @Success 200 Ret=200 操作成功
- // @router /resource/upload [post]
- func (this *ResourceController) ResourceUpload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- f, h, e := this.GetFile("file")
- if e != nil {
- br.Msg = "获取资源信息失败"
- br.ErrMsg = "获取资源信息失败, Err:" + e.Error()
- return
- }
- defer func() {
- _ = f.Close()
- }()
- uploadDir := "./static/"
- //uploadDir := "/Users/xi/Desktop/file"
- if e = os.MkdirAll(uploadDir, 766); e != nil {
- br.Msg = "存储目录创建失败"
- br.ErrMsg = "存储目录创建失败, Err:" + e.Error()
- return
- }
- //ossFileName := utils.GetRandStringNoSpecialChar(28) + ext
- filePath := uploadDir + "/" + h.Filename
- if e = this.SaveToFile("file", filePath); e != nil {
- br.Msg = "文件保存失败"
- br.ErrMsg = "文件保存失败, Err:" + e.Error()
- return
- }
- //defer func() {
- // _ = os.Remove(filePath)
- //}()
- br.Msg = "上传成功"
- br.Ret = 200
- br.Success = true
- }
|