Stream post videos to Spaces (#23)
CI / test (push) Successful in 6m31s

Pass the spooled video file through instead of buffering it in RAM, and sign Spaces uploads as UNSIGNED-PAYLOAD so the client does not hash the body first.

Reviewed-on: #23
Co-authored-by: codegirl-007 <s.raide@gmail.com>
This commit was merged in pull request #23.
This commit is contained in:
2026-08-31 08:22:32 +00:00
committed by codegirl007
parent a6e414853d
commit 84dea8ea5d
4 changed files with 79 additions and 27 deletions
+18 -3
View File
@@ -8,9 +8,11 @@ import (
"strings"
"github.com/aws/aws-sdk-go-v2/aws"
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"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"
)
// Uploader stores public avatar objects.
@@ -78,13 +80,26 @@ func NewSpaces(cfg SpacesConfig) Uploader {
return Disabled{}
}
client := s3.New(s3.Options{
Region: cfg.Region,
Credentials: credentials.NewStaticCredentialsProvider(cfg.Key, cfg.Secret, ""),
BaseEndpoint: aws.String(cfg.Endpoint),
Region: cfg.Region,
Credentials: credentials.NewStaticCredentialsProvider(cfg.Key, cfg.Secret, ""),
BaseEndpoint: aws.String(cfg.Endpoint),
RequestChecksumCalculation: aws.RequestChecksumCalculationWhenRequired,
APIOptions: []func(*middleware.Stack) error{
spacesUnsignedPayload,
},
})
return &spaces{client: client, cfg: cfg}
}
// spacesUnsignedPayload signs Spaces PUTs as UNSIGNED-PAYLOAD so the client
// can stream the body without hashing it first.
func spacesUnsignedPayload(stack *middleware.Stack) error {
if err := v4.SwapComputePayloadSHA256ForUnsignedPayloadMiddleware(stack); err != nil {
return v4.AddUnsignedPayloadMiddleware(stack)
}
return nil
}
func (s *spaces) Enabled() bool { return true }
func (s *spaces) Upload(ctx context.Context, obj FileUpload) (string, error) {