|
@@ -3,6 +3,7 @@ package logic
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "io"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"log"
|
|
"log"
|
|
"net/http"
|
|
"net/http"
|
|
@@ -15,6 +16,7 @@ import (
|
|
"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
|
|
"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
|
|
"bp.jydev.jianyu360.cn/CRM/application/service"
|
|
"bp.jydev.jianyu360.cn/CRM/application/service"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
+ "golang.org/x/text/encoding/charmap"
|
|
)
|
|
)
|
|
|
|
|
|
type FileUploadLogic struct {
|
|
type FileUploadLogic struct {
|
|
@@ -39,13 +41,15 @@ func (l *FileUploadLogic) FileUpload(req *types.FileUploadReq) (resp *types.Repl
|
|
status := 1
|
|
status := 1
|
|
defer file.Close()
|
|
defer file.Close()
|
|
bt, _ := ioutil.ReadAll(file)
|
|
bt, _ := ioutil.ReadAll(file)
|
|
|
|
+ utf8Filename, err := convertToUTF8(header.Filename)
|
|
|
|
+
|
|
up, err := cm.FileCenterRpc.Upload(l.ctx, &fpb.UploadReq{
|
|
up, err := cm.FileCenterRpc.Upload(l.ctx, &fpb.UploadReq{
|
|
File: bt,
|
|
File: bt,
|
|
OssBucketName: cm.C.OssBucketName,
|
|
OssBucketName: cm.C.OssBucketName,
|
|
OssUrl: cm.C.OssUrl,
|
|
OssUrl: cm.C.OssUrl,
|
|
Name: header.Filename,
|
|
Name: header.Filename,
|
|
})
|
|
})
|
|
- log.Println("=====", header.Filename)
|
|
|
|
|
|
+ log.Println("=====", header.Filename, "~~", utf8Filename)
|
|
if up == nil || up.Url == "" {
|
|
if up == nil || up.Url == "" {
|
|
resp.Error_code = -1
|
|
resp.Error_code = -1
|
|
resp.Error_msg = "上传失败"
|
|
resp.Error_msg = "上传失败"
|
|
@@ -99,3 +103,14 @@ func (l *FileUploadLogic) FileUpload(req *types.FileUploadReq) (resp *types.Repl
|
|
resp.Data = data
|
|
resp.Data = data
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func convertToUTF8(iso8859Filename string) (string, error) {
|
|
|
|
+ iso8859Decoder := charmap.ISO8859_1.NewDecoder()
|
|
|
|
+ utf8Bytes, err := io.ReadAll(iso8859Decoder.Reader(strings.NewReader(iso8859Filename)))
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ utf8Filename := string(utf8Bytes)
|
|
|
|
+ return utf8Filename, nil
|
|
|
|
+}
|