fix:修复
This commit is contained in:
parent
8b42c41bc5
commit
f87842deb4
|
@ -67,7 +67,7 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
|
|||
|
||||
// 定义存储桶名称
|
||||
var bucketName *string
|
||||
var apiType int64 = 2
|
||||
var apiType int64 = req.ApiType
|
||||
|
||||
// 根据类别选择存储桶
|
||||
switch req.UploadBucket {
|
||||
|
@ -96,7 +96,7 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
|
|||
uploadUrl.ResourceId = resourceId
|
||||
uploadUrl.ResourceUrl = *resourceInfo.ResourceUrl
|
||||
} else {
|
||||
dist, err := file.FileBase64ToByte(req.FileData)
|
||||
dist, contentType, err := file.FileBase64ToByte(req.FileData)
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
|
@ -134,7 +134,7 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
|
|||
ResourceId: resourceId,
|
||||
UserId: &userId,
|
||||
GuestId: &guestId,
|
||||
ResourceType: &req.FileType,
|
||||
ResourceType: &contentType,
|
||||
ResourceUrl: &url,
|
||||
Version: &version,
|
||||
UploadedAt: &nowTime,
|
||||
|
|
|
@ -177,6 +177,7 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq,
|
|||
logx.Error(err)
|
||||
uploadUrl.Status = 0
|
||||
} else {
|
||||
contentType := http.DetectContentType(uploadDataInfo.FileData)
|
||||
var url = s3req.HTTPRequest.URL.String()
|
||||
// 打印请求URL
|
||||
logx.Info(url)
|
||||
|
@ -189,7 +190,7 @@ func (l *UploadFilesBackendLogic) UploadFilesBackend(req *types.UploadFilesReq,
|
|||
ResourceId: resourceId,
|
||||
UserId: &userId,
|
||||
GuestId: &guestId,
|
||||
ResourceType: &uploadDataInfo.FileType,
|
||||
ResourceType: &contentType,
|
||||
ResourceUrl: &url,
|
||||
Version: &version,
|
||||
UploadedAt: &nowTime,
|
||||
|
|
|
@ -110,6 +110,13 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
|||
// }
|
||||
// resultStr = string(b)
|
||||
|
||||
// 上传图片
|
||||
var reqs types.UploadFileBaseReq
|
||||
// reqs.FileType =
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
NewUploadFileBaseLogic(l.ctx, l.svcCtx).UploadFileBase(&reqs, userinfo)
|
||||
|
||||
var module = "logo"
|
||||
var nowTime = time.Now().Unix()
|
||||
// 新增记录
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
type UploadFileBaseReq struct {
|
||||
FileType string `form:"file_type"` // 上传文件类型
|
||||
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内
|
||||
FileKey string `form:"file_key"` // 上传唯一标识信息
|
||||
FileData string `form:"file_data"` // 上传文件额外信息
|
||||
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
|
||||
|
|
|
@ -46,7 +46,7 @@ service upload {
|
|||
|
||||
type (
|
||||
UploadFileBaseReq {
|
||||
FileType string `form:"file_type"` // 上传文件类型
|
||||
ApiType int64 `form:"api_type,options=[1,2],default=1"` // 调用类型:1=对外,2=对内
|
||||
FileKey string `form:"file_key"` // 上传唯一标识信息
|
||||
FileData string `form:"file_data"` // 上传文件额外信息
|
||||
Metadata string `form:"meta_data,optional"` // 上传文件额外信息
|
||||
|
|
|
@ -2,16 +2,17 @@ package file
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func FileBase64ToByte(fileData string) ([]byte, error) {
|
||||
func FileBase64ToByte(fileData string) ([]byte, string, error) {
|
||||
RBase64Point := strings.LastIndex(fileData, ";base64,") + 8
|
||||
fileDataStr := fileData[RBase64Point:]
|
||||
dist, err := base64.StdEncoding.DecodeString(fileDataStr)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, "", err
|
||||
}
|
||||
return dist, nil
|
||||
contentType := http.DetectContentType(dist)
|
||||
return dist, contentType, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user