Skip to content

Commit 43b305d

Browse files
wty-BryantTianyi Wang
andauthored
Feat s3 transfer manager v2 PutObject (#2733)
* recommit transfer manager v2 files * change pool to store slice pointer * add integ test for putobject * update go mod * minor changes for v0.1.0 * update tags * update tags * update integ test dependency version * change err var name * update go mod * change input/output type comment * minor change --------- Co-authored-by: Tianyi Wang <[email protected]>
1 parent 061540b commit 43b305d

File tree

18 files changed

+3039
-4
lines changed

18 files changed

+3039
-4
lines changed

feature/s3/transfermanager/api.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package transfermanager
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/s3"
7+
)
8+
9+
// S3APIClient defines an interface doing S3 client side operations for transfer manager
10+
type S3APIClient interface {
11+
PutObject(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) (*s3.PutObjectOutput, error)
12+
UploadPart(context.Context, *s3.UploadPartInput, ...func(*s3.Options)) (*s3.UploadPartOutput, error)
13+
CreateMultipartUpload(context.Context, *s3.CreateMultipartUploadInput, ...func(*s3.Options)) (*s3.CreateMultipartUploadOutput, error)
14+
CompleteMultipartUpload(context.Context, *s3.CompleteMultipartUploadInput, ...func(*s3.Options)) (*s3.CompleteMultipartUploadOutput, error)
15+
AbortMultipartUpload(context.Context, *s3.AbortMultipartUploadInput, ...func(*s3.Options)) (*s3.AbortMultipartUploadOutput, error)
16+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package transfermanager
2+
3+
import (
4+
"github.com/aws/aws-sdk-go-v2/aws"
5+
)
6+
7+
const userAgentKey = "s3-transfer"
8+
9+
// defaultMaxUploadParts is the maximum allowed number of parts in a multi-part upload
10+
// on Amazon S3.
11+
const defaultMaxUploadParts = 10000
12+
13+
// defaultPartSizeBytes is the default part size when transferring objects to/from S3
14+
const minPartSizeBytes = 1024 * 1024 * 8
15+
16+
// defaultMultipartUploadThreshold is the default size threshold in bytes indicating when to use multipart upload.
17+
const defaultMultipartUploadThreshold = 1024 * 1024 * 16
18+
19+
// defaultTransferConcurrency is the default number of goroutines to spin up when
20+
// using PutObject().
21+
const defaultTransferConcurrency = 5
22+
23+
// Client provides the API client to make operations call for Amazon Simple
24+
// Storage Service's Transfer Manager
25+
// It is safe to call Client methods concurrently across goroutines.
26+
type Client struct {
27+
options Options
28+
}
29+
30+
// New returns an initialized Client from the client Options. Provide
31+
// more functional options to further configure the Client
32+
func New(s3Client S3APIClient, opts Options, optFns ...func(*Options)) *Client {
33+
opts.S3 = s3Client
34+
for _, fn := range optFns {
35+
fn(&opts)
36+
}
37+
38+
resolveConcurrency(&opts)
39+
resolvePartSizeBytes(&opts)
40+
resolveChecksumAlgorithm(&opts)
41+
resolveMultipartUploadThreshold(&opts)
42+
43+
return &Client{
44+
options: opts,
45+
}
46+
}
47+
48+
// NewFromConfig returns a new Client from the provided s3 config
49+
func NewFromConfig(s3Client S3APIClient, cfg aws.Config, optFns ...func(*Options)) *Client {
50+
return New(s3Client, Options{}, optFns...)
51+
}

0 commit comments

Comments
 (0)