This commit is contained in:
XM-GO
2023-08-22 15:17:14 +08:00
parent 85f4f328f4
commit 4344771547
143 changed files with 13004 additions and 6957 deletions

View File

@@ -3,33 +3,26 @@ package api
import (
"fmt"
"github.com/XM-GO/PandaKit/biz"
filek "github.com/XM-GO/PandaKit/file"
"github.com/XM-GO/PandaKit/restfulx"
"github.com/kakuilan/kgo"
"net/http"
"os"
"pandax/pkg/tool"
"path"
"strings"
"time"
)
type UploadApi struct{}
const filePath = "uploads/file"
// UploadImage 图片上传
// UploadImage 图片上传
func (up *UploadApi) UploadImage(rc *restfulx.ReqCtx) {
_, fileHeader, err := rc.Request.Request.FormFile("imagefile")
_, fileHeader, err := rc.Request.Request.FormFile("file")
biz.ErrIsNil(err, "请传入文件")
ext := path.Ext(fileHeader.Filename)
// 读取文件名并加密
name := strings.TrimSuffix(fileHeader.Filename, ext)
name = kgo.KStr.Md5(name, 32)
// 拼接新文件名
filename := name + "_" + time.Now().Format("20060102150405") + ext
filek.SaveUploadedFile(fileHeader, fmt.Sprintf("%s/%s", filePath, filename))
local := &tool.Local{Path: filePath}
link, fileName, err := local.UploadFile(fileHeader)
biz.ErrIsNil(err, "文件上传失败")
rc.ResData = map[string]string{"fileName": name}
rc.ResData = map[string]string{"fileName": fileName, "filePath": link}
}
func (up *UploadApi) GetImage(rc *restfulx.ReqCtx) {