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