feat: add rustfs direct upload endpoint
Build docker and publish / build (20.15.1) (push) Failing after 8m36s
Build docker and publish / build (20.15.1) (push) Failing after 8m36s
This commit is contained in:
+21
-2
@@ -3,6 +3,7 @@ package storage
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -22,11 +23,15 @@ type PresignUploadResult struct {
|
||||
}
|
||||
|
||||
type ObjectMeta struct {
|
||||
ETag string
|
||||
ContentType string
|
||||
ETag string
|
||||
ContentType string
|
||||
ContentLength int64
|
||||
}
|
||||
|
||||
type PutObjectResult struct {
|
||||
ETag string
|
||||
}
|
||||
|
||||
type S3Store struct {
|
||||
cfg config.S3Config
|
||||
client *s3.Client
|
||||
@@ -96,6 +101,20 @@ func (s *S3Store) HeadObject(ctx context.Context, objectKey string) (*ObjectMeta
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *S3Store) PutObject(ctx context.Context, objectKey string, body io.Reader, size int64, contentType string) (*PutObjectResult, error) {
|
||||
resp, err := s.client.PutObject(ctx, &s3.PutObjectInput{
|
||||
Bucket: aws.String(s.cfg.Bucket),
|
||||
Key: aws.String(objectKey),
|
||||
Body: body,
|
||||
ContentLength: aws.Int64(size),
|
||||
ContentType: aws.String(contentType),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &PutObjectResult{ETag: strings.Trim(aws.ToString(resp.ETag), "\"")}, nil
|
||||
}
|
||||
|
||||
func (s *S3Store) BuildObjectURL(objectKey string) string {
|
||||
if s.cfg.PublicBaseURL != "" {
|
||||
return strings.TrimRight(s.cfg.PublicBaseURL, "/") + "/" + strings.TrimLeft(objectKey, "/")
|
||||
|
||||
Reference in New Issue
Block a user