putObjectDo - executes the put object http operation. NOTE: You must have WRITE permissions on a bucket to add an object to it.
(ctx context.Context, bucketName, objectName string, reader io.Reader, md5Base64, sha256Hex string, size int64, opts PutObjectOptions)
| 732 | // putObjectDo - executes the put object http operation. |
| 733 | // NOTE: You must have WRITE permissions on a bucket to add an object to it. |
| 734 | func (c *Client) putObjectDo(ctx context.Context, bucketName, objectName string, reader io.Reader, md5Base64, sha256Hex string, size int64, opts PutObjectOptions) (UploadInfo, error) { |
| 735 | // Input validation. |
| 736 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 737 | return UploadInfo{}, err |
| 738 | } |
| 739 | if err := s3utils.CheckValidObjectName(objectName); err != nil { |
| 740 | return UploadInfo{}, err |
| 741 | } |
| 742 | // Set headers. |
| 743 | customHeader := opts.Header() |
| 744 | |
| 745 | // Populate request metadata. |
| 746 | reqMetadata := requestMetadata{ |
| 747 | bucketName: bucketName, |
| 748 | objectName: objectName, |
| 749 | customHeader: customHeader, |
| 750 | contentBody: reader, |
| 751 | contentLength: size, |
| 752 | contentMD5Base64: md5Base64, |
| 753 | contentSHA256Hex: sha256Hex, |
| 754 | streamSha256: !opts.DisableContentSha256, |
| 755 | } |
| 756 | // Add CRC when client supports it, MD5 is not set, not Google and we don't add SHA256 to chunks. |
| 757 | addCrc := c.trailingHeaderSupport && md5Base64 == "" && !s3utils.IsGoogleEndpoint(*c.endpointURL) && (opts.DisableContentSha256 || c.secure) |
| 758 | if opts.Checksum.IsSet() { |
| 759 | reqMetadata.addCrc = &opts.Checksum |
| 760 | } else if addCrc { |
| 761 | // If user has added checksums, don't add them ourselves. |
| 762 | for k := range opts.UserMetadata { |
| 763 | if strings.HasPrefix(strings.ToLower(k), "x-amz-checksum-") { |
| 764 | addCrc = false |
| 765 | } |
| 766 | } |
| 767 | if addCrc { |
| 768 | opts.AutoChecksum.SetDefault(ChecksumFullObjectCRC32C) |
| 769 | reqMetadata.addCrc = &opts.AutoChecksum |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | if opts.Internal.SourceVersionID != "" { |
| 774 | if opts.Internal.SourceVersionID != nullVersionID { |
| 775 | if _, err := uuid.Parse(opts.Internal.SourceVersionID); err != nil { |
| 776 | return UploadInfo{}, errInvalidArgument(err.Error()) |
| 777 | } |
| 778 | } |
| 779 | urlValues := make(url.Values) |
| 780 | urlValues.Set("versionId", opts.Internal.SourceVersionID) |
| 781 | reqMetadata.queryValues = urlValues |
| 782 | } |
| 783 | |
| 784 | // Execute PUT an objectName. |
| 785 | resp, err := c.executeMethod(ctx, http.MethodPut, reqMetadata) |
| 786 | defer closeResponse(resp) |
| 787 | if err != nil { |
| 788 | return UploadInfo{}, err |
| 789 | } |
| 790 | if resp != nil { |
| 791 | if resp.StatusCode != http.StatusOK { |
no test coverage detected