UPDATE: try fix move s3
All checks were successful
Build and Release / release (push) Successful in 1m7s

This commit is contained in:
2026-04-09 16:06:42 +07:00
parent d98a462f5c
commit baa07609b2

View File

@@ -7,14 +7,16 @@ import (
"net/url"
"time"
ffconfig "history-api/pkg/config"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/aws/smithy-go/middleware"
smithyhttp "github.com/aws/smithy-go/transport/http"
"github.com/rs/zerolog/log"
ffconfig "history-api/pkg/config"
)
type UploadOptions struct {
@@ -90,6 +92,20 @@ func NewS3Storage() (Storage, error) {
client := s3.NewFromConfig(cfg, func(o *s3.Options) {
o.BaseEndpoint = aws.String(endpoint)
o.UsePathStyle = true
o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error {
return stack.Build.Add(middleware.BuildMiddlewareFunc(
"AddEmptyContentLength",
func(ctx context.Context, in middleware.BuildInput, next middleware.BuildHandler) (
out middleware.BuildOutput, metadata middleware.Metadata, err error,
) {
req, ok := in.Request.(*smithyhttp.Request)
if ok && req.Method == "PUT" && req.Header.Get("Content-Length") == "" {
req.Header.Set("Content-Length", "0")
}
return next.HandleBuild(ctx, in)
},
), middleware.After)
})
})
return &s3Storage{
@@ -110,6 +126,7 @@ func (s *s3Storage) Move(ctx context.Context, src *MoveOptions, dest *MoveOption
Bucket: aws.String(dest.Bucket),
Key: aws.String(dest.Key),
CopySource: aws.String(copySource),
MetadataDirective: types.MetadataDirectiveCopy,
})
if err != nil {
return fmt.Errorf("failed to copy object: %w", err)