-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ISSUE 50] Adding in an example for multipart upload #168
base: main
Are you sure you want to change the base?
Conversation
@Erikvv, let me know if you have any suggestions! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. I don't have merge permission but I'll review.
Suggestion: have two examples: one for upload+share, and one for multipart upload.
@@ -129,6 +140,114 @@ func CreatePublicSharedLink(ctx context.Context, accessGrant, bucketName, object | |||
return url, nil | |||
} | |||
|
|||
func MultipartUpload(ctx context.Context, accessGrant, bucketName, objectKey string, contents1, contents2 []byte) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verb first, so UploadMultipart
return nil | ||
} | ||
|
||
func createMultipartData() (contents1, contents2 []byte) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Pascal case, CreateMultipartData
Okay, thank you @Erikvv! I will make the changes. Do you know who has merge privileges? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good, just a bunch of nitpicks.
We can do those ourselves as well if you are busy... but if you'd like to do these yourself, then I'm definitely not stopping you :).
Thank you.
func UploadAndDownloadData(ctx context.Context, | ||
accessGrant, bucketName, uploadKey string, dataToUpload []byte) error { | ||
|
||
func CreateProjectAndConfirmBucket(ctx context.Context, accessGrant, bucketName string) (*uplink.Project, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func CreateProjectAndConfirmBucket(ctx context.Context, accessGrant, bucketName string) (*uplink.Project, error) { | |
// OpenProjectAndEnsureBucket shows how to open a project and check that the bucket exists and create if it doesn't. | |
func OpenProjectAndEnsureBucket(ctx context.Context, accessGrant, bucketName string) (*uplink.Project, error) { |
Note, it's "OpenProject", because it actually doesn't create a new project when it's missing -- just opens a new connection to the project.
Similar reason for the "EnsureBucket" -- "Confirm" would somewhat imply that it would fail if the bucket doesn't exist.
@@ -129,6 +140,114 @@ func CreatePublicSharedLink(ctx context.Context, accessGrant, bucketName, object | |||
return url, nil | |||
} | |||
|
|||
func MultipartUpload(ctx context.Context, accessGrant, bucketName, objectKey string, contents1, contents2 []byte) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func MultipartUpload(ctx context.Context, accessGrant, bucketName, objectKey string, contents1, contents2 []byte) error { | |
// MultipartUpload demonstrates how to upload object in multiple parts. | |
func MultipartUpload(ctx context.Context, accessGrant, bucketName, objectKey string, first, second []byte) error { |
The change from contents1
-> to first
, because when reading code the suffix numbers can get confusing. Especially when they are interleaved in places. It's not a big problem in this case, but we like to keep this consistent. (Also the relevant error messages need updating as well.)
Using firstPart
or firstContent
would be also fine.
// Write the contents to part 1 upload | ||
_, err = part1.Write(contents1) | ||
if err != nil { | ||
return fmt.Errorf("unable to write to part 1: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("unable to write to part 1: %v", err) | |
_ = part1.Close() | |
return fmt.Errorf("unable to write to part 1: %v", err) |
// Write the contents to part 2 upload | ||
_, err = part2.Write(contents2) | ||
if err != nil { | ||
return fmt.Errorf("unable to write to part 2: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("unable to write to part 2: %v", err) | |
_ = part2.Close() | |
return fmt.Errorf("unable to write to part 2: %v", err) |
return nil | ||
} | ||
|
||
func createMultipartData() (contents1, contents2 []byte) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this function you can use:
firstPart := bytes.Repeat([]byte("abcdefghijklm"), 1e6)
secondPart := bytes.Repeat([]byte("0123456789"), 1e6)
|
||
largeObjectKey := "foo/bar/large" | ||
|
||
largeContents1, largeContents2 := createMultipartData() | ||
|
||
err = MultipartUpload(ctx, *accessGrant, bucketName, largeObjectKey, largeContents1, largeContents2) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "creating mulipart upload failed:", err) | ||
os.Exit(1) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
largeObjectKey := "foo/bar/large" | |
largeContents1, largeContents2 := createMultipartData() | |
err = MultipartUpload(ctx, *accessGrant, bucketName, largeObjectKey, largeContents1, largeContents2) | |
if err != nil { | |
fmt.Fprintln(os.Stderr, "creating mulipart upload failed:", err) | |
os.Exit(1) | |
} | |
largeObjectKey := "foo/bar/large" | |
largeFirstPart := bytes.Repeat([]byte("abcdefghijklm"), 1e6) | |
largeSecondPart := bytes.Repeat([]byte("0123456789"), 1e6) | |
err = MultipartUpload(ctx, *accessGrant, bucketName, largeObjectKey, largeFirstPart, largeSecondPart) | |
if err != nil { | |
fmt.Fprintln(os.Stderr, "creating mulipart upload failed:", err) | |
os.Exit(1) | |
} |
What: Adding in a walkthrough example for a multipart upload
Link: #50
Why: There currently isn't an example of how to do a multipart upload so I had to do a lot of diggint
Please describe the tests:
No tests just running it locally and verifying it works
Please describe the performance impact: N/A
Code Review Checklist (to be filled out by reviewer)