fix:文件上传--base64

This commit is contained in:
Hiven 2023-08-07 12:02:11 +08:00
parent 869873deda
commit 3d82709b7e
2 changed files with 20 additions and 5 deletions

View File

@ -1,13 +1,12 @@
package logic
import (
"encoding/base64"
"fmt"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/file"
"fusenapi/utils/hash"
"strings"
"time"
"context"
@ -97,12 +96,11 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
uploadUrl.ResourceId = resourceId
uploadUrl.ResourceUrl = *resourceInfo.ResourceUrl
} else {
RBase64Point := strings.LastIndex(req.FileData, ";base64,") + 8
req.FileData = req.FileData[RBase64Point:]
dist, err := base64.StdEncoding.DecodeString(req.FileData)
dist, err := file.FileBase64ToByte(req.FileData)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,base64tobyte error")
}
// 创建S3对象存储请求

17
utils/file/base64.go Normal file
View File

@ -0,0 +1,17 @@
package file
import (
"encoding/base64"
"strings"
)
func FileBase64ToByte(fileData string) ([]byte, error) {
RBase64Point := strings.LastIndex(fileData, ";base64,") + 8
fileDataStr := fileData[RBase64Point:]
dist, err := base64.StdEncoding.DecodeString(fileDataStr)
if err != nil {
return nil, err
}
return dist, nil
}