You've already forked VptPassiveAdapter
refactor(api): 移除上传文件时的Content-Type参数
- 删除UploadFileToOSS函数中的contentType参数 - 更新所有调用UploadFileToOSS的地方,移除传递的Content-Type值 - 简化上传逻辑,不再手动设置HTTP请求头中的Content-Type - 依赖服务器端自动检测文件类型进行处理
This commit is contained in:
@@ -189,12 +189,11 @@ func SubmitFailure(ctx context.Context, taskID int64, errorCode, errorMessage st
|
||||
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))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", contentType)
|
||||
|
||||
resp, err := GetUploadClient().Do(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"ZhenTuLocalPassiveAdapter/logger"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
@@ -25,7 +26,7 @@ func UploadFaceData(ctx context.Context, scenicId int64, deviceNo string, faceIm
|
||||
// Upload Face Image
|
||||
g.Go(func() error {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -35,7 +36,7 @@ func UploadFaceData(ctx context.Context, scenicId int64, deviceNo string, faceIm
|
||||
// Upload Thumbnail Image
|
||||
g.Go(func() error {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -45,7 +46,7 @@ func UploadFaceData(ctx context.Context, scenicId int64, deviceNo string, faceIm
|
||||
// Upload Source Image
|
||||
g.Go(func() error {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user