refactor(api): 移除上传文件时的Content-Type参数

- 删除UploadFileToOSS函数中的contentType参数
- 更新所有调用UploadFileToOSS的地方,移除传递的Content-Type值
- 简化上传逻辑,不再手动设置HTTP请求头中的Content-Type
- 依赖服务器端自动检测文件类型进行处理
This commit is contained in:
2025-11-24 17:56:05 +08:00
parent 67968abcf3
commit f10b68e487
2 changed files with 5 additions and 5 deletions

View File

@@ -189,12 +189,11 @@ func SubmitFailure(ctx context.Context, taskID int64, errorCode, errorMessage st
return nil return nil
} }
func UploadFileToOSS(ctx context.Context, uploadUrl string, data []byte, contentType string) error { func UploadFileToOSS(ctx context.Context, uploadUrl string, data []byte) error {
req, err := http.NewRequestWithContext(ctx, "PUT", uploadUrl, bytes.NewReader(data)) req, err := http.NewRequestWithContext(ctx, "PUT", uploadUrl, bytes.NewReader(data))
if err != nil { if err != nil {
return err return err
} }
req.Header.Set("Content-Type", contentType)
resp, err := GetUploadClient().Do(req) resp, err := GetUploadClient().Do(req)
if err != nil { if err != nil {

View File

@@ -4,6 +4,7 @@ import (
"ZhenTuLocalPassiveAdapter/logger" "ZhenTuLocalPassiveAdapter/logger"
"context" "context"
"fmt" "fmt"
"go.uber.org/zap" "go.uber.org/zap"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
@@ -25,7 +26,7 @@ func UploadFaceData(ctx context.Context, scenicId int64, deviceNo string, faceIm
// Upload Face Image // Upload Face Image
g.Go(func() error { g.Go(func() error {
if len(faceImg) > 0 { if len(faceImg) > 0 {
if err := UploadFileToOSS(subCtx, uploadConfig.FaceUploadURL, faceImg, "image/jpeg"); err != nil { if err := UploadFileToOSS(subCtx, uploadConfig.FaceUploadURL, faceImg); err != nil {
return fmt.Errorf("upload face image failed: %w", err) return fmt.Errorf("upload face image failed: %w", err)
} }
} }
@@ -35,7 +36,7 @@ func UploadFaceData(ctx context.Context, scenicId int64, deviceNo string, faceIm
// Upload Thumbnail Image // Upload Thumbnail Image
g.Go(func() error { g.Go(func() error {
if len(thumbImg) > 0 { if len(thumbImg) > 0 {
if err := UploadFileToOSS(subCtx, uploadConfig.ThumbnailUploadURL, thumbImg, "image/jpeg"); err != nil { if err := UploadFileToOSS(subCtx, uploadConfig.ThumbnailUploadURL, thumbImg); err != nil {
return fmt.Errorf("upload thumbnail image failed: %w", err) return fmt.Errorf("upload thumbnail image failed: %w", err)
} }
} }
@@ -45,7 +46,7 @@ func UploadFaceData(ctx context.Context, scenicId int64, deviceNo string, faceIm
// Upload Source Image // Upload Source Image
g.Go(func() error { g.Go(func() error {
if len(srcImg) > 0 { if len(srcImg) > 0 {
if err := UploadFileToOSS(subCtx, uploadConfig.SourceUploadURL, srcImg, "image/jpeg"); err != nil { if err := UploadFileToOSS(subCtx, uploadConfig.SourceUploadURL, srcImg); err != nil {
return fmt.Errorf("upload source image failed: %w", err) return fmt.Errorf("upload source image failed: %w", err)
} }
} }