From 4ee9a0b0300561470b16427afbcad5a0395a9765 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期二, 26 十二月 2023 09:48:10 +0800
Subject: [PATCH] 模版上传时保留模版原名称
---
utils/upload/seaweed.go | 7 +++----
controllers/attachment.go | 5 +++--
controllers/operation.go | 5 +++--
3 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/controllers/attachment.go b/controllers/attachment.go
index b0de492..3729024 100644
--- a/controllers/attachment.go
+++ b/controllers/attachment.go
@@ -36,6 +36,7 @@
var attachmentList []*models.Attachment
for _, fileHeader := range files {
ext := strings.ToLower(path.Ext(fileHeader.Filename))[1:]
+ fileParams := strings.Split(fileHeader.Filename, ".")
var fileType constvar.FileType
if value, ok := constvar.FileExtMap[ext]; ok {
fileType = value
@@ -57,7 +58,7 @@
buffer := new(bytes.Buffer)
_, _ = io.Copy(buffer, file)
fileBytes := buffer.Bytes()
- fileUrl, err := upload.UploadFileToSeaWeed(string(fileType), ext, fileBytes)
+ fileUrl, err := upload.UploadFileToSeaWeed(string(fileType), fileHeader.Filename, fileBytes)
if err != nil {
logx.Errorf("file upload err: %v", err)
util.ResponseFormat(c, code.RequestParamError, err.Error())
@@ -79,7 +80,7 @@
util.ResponseFormat(c, code.RequestParamError, "鐢熸垚缂╃暐鍥惧け璐ワ細"+err.Error())
return
}
- thumbnailUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_Thumbnail), ext, thumbnailBytes)
+ thumbnailUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_Thumbnail), fileParams[0]+"thumbnail."+ext, thumbnailBytes)
if err != nil {
logx.Errorf("file upload err: %v", err)
util.ResponseFormat(c, code.RequestParamError, err.Error())
diff --git a/controllers/operation.go b/controllers/operation.go
index e467303..5761f62 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -6,6 +6,7 @@
"errors"
"fmt"
"github.com/gin-gonic/gin"
+ uuid "github.com/satori/go.uuid"
"github.com/shopspring/decimal"
"github.com/xuri/excelize/v2"
"gorm.io/gorm"
@@ -1052,7 +1053,7 @@
return "", err
}
- fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), "xlsx", buf.Bytes())
+ fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), uuid.NewV4().String()+".xlsx", buf.Bytes())
if err != nil {
logx.Errorf("file upload err: %v", err)
return "", err
@@ -1129,7 +1130,7 @@
return "", err
}
- fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), "xlsx", buf.Bytes())
+ fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), uuid.NewV4().String()+".xlsx", buf.Bytes())
if err != nil {
logx.Errorf("file upload err: %v", err)
return "", err
diff --git a/utils/upload/seaweed.go b/utils/upload/seaweed.go
index 40eea74..0efd120 100644
--- a/utils/upload/seaweed.go
+++ b/utils/upload/seaweed.go
@@ -2,13 +2,12 @@
import (
"basic.com/fileserver/WeedFSClient.git"
- uuid "github.com/satori/go.uuid"
"time"
"wms/conf"
"wms/pkg/logx"
)
-func UploadFileToSeaWeed(fileType, ext string, fileBytes []byte) (string, error) {
+func UploadFileToSeaWeed(fileType, fileName string, fileBytes []byte) (string, error) {
//assignUrl := conf.WebConf.FileServer + "/dir/assign?collection=" + time.Now().Format("2006-01-02 15:04:05")[:10] + "-" + conf.WebConf.ServerId + "-" + fileType
assignUrl := conf.WebConf.FileServer + "/dir/assign?collection=12345-" + conf.WebConf.ServerId + "-" + fileType
@@ -18,7 +17,7 @@
return picUrl, err
}
- picFileName := uuid.NewV4().String() + "." + ext
- go WeedFSClient.UploadFile(picUrl, picFileName, fileBytes, 3*time.Second)
+ //picFileName := uuid.NewV4().String() + "." + ext
+ go WeedFSClient.UploadFile(picUrl, fileName, fileBytes, 3*time.Second)
return picUrl, nil
}
--
Gitblit v1.8.0