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:
+18
-3
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user