@@ -108,7 +108,9 @@ func (c *Client) putObjectMultipartStreamFromReadAt(ctx context.Context, bucketN
108
108
if err != nil {
109
109
return UploadInfo {}, err
110
110
}
111
-
111
+ if opts .Checksum .IsSet () {
112
+ opts .AutoChecksum = opts .Checksum
113
+ }
112
114
withChecksum := c .trailingHeaderSupport
113
115
if withChecksum {
114
116
if opts .UserMetadata == nil {
@@ -304,6 +306,11 @@ func (c *Client) putObjectMultipartStreamOptionalChecksum(ctx context.Context, b
304
306
return UploadInfo {}, err
305
307
}
306
308
309
+ if opts .Checksum .IsSet () {
310
+ opts .AutoChecksum = opts .Checksum
311
+ opts .SendContentMd5 = false
312
+ }
313
+
307
314
if ! opts .SendContentMd5 {
308
315
if opts .UserMetadata == nil {
309
316
opts .UserMetadata = make (map [string ]string , 1 )
@@ -463,7 +470,10 @@ func (c *Client) putObjectMultipartStreamParallel(ctx context.Context, bucketNam
463
470
if err = s3utils .CheckValidObjectName (objectName ); err != nil {
464
471
return UploadInfo {}, err
465
472
}
466
-
473
+ if opts .Checksum .IsSet () {
474
+ opts .SendContentMd5 = false
475
+ opts .AutoChecksum = opts .Checksum
476
+ }
467
477
if ! opts .SendContentMd5 {
468
478
if opts .UserMetadata == nil {
469
479
opts .UserMetadata = make (map [string ]string , 1 )
@@ -555,7 +565,7 @@ func (c *Client) putObjectMultipartStreamParallel(ctx context.Context, bucketNam
555
565
// Calculate md5sum.
556
566
customHeader := make (http.Header )
557
567
if ! opts .SendContentMd5 {
558
- // Add CRC32C instead.
568
+ // Add Checksum instead.
559
569
crc .Reset ()
560
570
crc .Write (buf [:length ])
561
571
cSum := crc .Sum (nil )
@@ -677,6 +687,9 @@ func (c *Client) putObject(ctx context.Context, bucketName, objectName string, r
677
687
if opts .SendContentMd5 && s3utils .IsGoogleEndpoint (* c .endpointURL ) && size < 0 {
678
688
return UploadInfo {}, errInvalidArgument ("MD5Sum cannot be calculated with size '-1'" )
679
689
}
690
+ if opts .Checksum .IsSet () {
691
+ opts .SendContentMd5 = false
692
+ }
680
693
681
694
var readSeeker io.Seeker
682
695
if size > 0 {
@@ -746,17 +759,6 @@ func (c *Client) putObjectDo(ctx context.Context, bucketName, objectName string,
746
759
// Set headers.
747
760
customHeader := opts .Header ()
748
761
749
- // Add CRC when client supports it, MD5 is not set, not Google and we don't add SHA256 to chunks.
750
- addCrc := c .trailingHeaderSupport && md5Base64 == "" && ! s3utils .IsGoogleEndpoint (* c .endpointURL ) && (opts .DisableContentSha256 || c .secure )
751
-
752
- if addCrc {
753
- // If user has added checksums, don't add them ourselves.
754
- for k := range opts .UserMetadata {
755
- if strings .HasPrefix (strings .ToLower (k ), "x-amz-checksum-" ) {
756
- addCrc = false
757
- }
758
- }
759
- }
760
762
// Populate request metadata.
761
763
reqMetadata := requestMetadata {
762
764
bucketName : bucketName ,
@@ -768,10 +770,23 @@ func (c *Client) putObjectDo(ctx context.Context, bucketName, objectName string,
768
770
contentSHA256Hex : sha256Hex ,
769
771
streamSha256 : ! opts .DisableContentSha256 ,
770
772
}
771
- if addCrc {
772
- opts .AutoChecksum .SetDefault (ChecksumCRC32C )
773
- reqMetadata .addCrc = & opts .AutoChecksum
773
+ // Add CRC when client supports it, MD5 is not set, not Google and we don't add SHA256 to chunks.
774
+ addCrc := c .trailingHeaderSupport && md5Base64 == "" && ! s3utils .IsGoogleEndpoint (* c .endpointURL ) && (opts .DisableContentSha256 || c .secure )
775
+ if opts .Checksum .IsSet () {
776
+ reqMetadata .addCrc = & opts .Checksum
777
+ } else if addCrc {
778
+ // If user has added checksums, don't add them ourselves.
779
+ for k := range opts .UserMetadata {
780
+ if strings .HasPrefix (strings .ToLower (k ), "x-amz-checksum-" ) {
781
+ addCrc = false
782
+ }
783
+ }
784
+ if addCrc {
785
+ opts .AutoChecksum .SetDefault (ChecksumCRC32C )
786
+ reqMetadata .addCrc = & opts .AutoChecksum
787
+ }
774
788
}
789
+
775
790
if opts .Internal .SourceVersionID != "" {
776
791
if opts .Internal .SourceVersionID != nullVersionID {
777
792
if _ , err := uuid .Parse (opts .Internal .SourceVersionID ); err != nil {
0 commit comments