diff --git a/server/upload/internal/logic/uploadfilebaselogic.go b/server/upload/internal/logic/uploadfilebaselogic.go index 28a8ae1c..46c210c0 100644 --- a/server/upload/internal/logic/uploadfilebaselogic.go +++ b/server/upload/internal/logic/uploadfilebaselogic.go @@ -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对象存储请求 diff --git a/utils/file/base64.go b/utils/file/base64.go new file mode 100644 index 00000000..84825501 --- /dev/null +++ b/utils/file/base64.go @@ -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 +}