public IRequest Marshall(CopyObjectRequest copyObjectRequest) { var sourceKey = AmazonS3Util.RemoveLeadingSlash(copyObjectRequest.SourceKey); var destinationKey = AmazonS3Util.RemoveLeadingSlash(copyObjectRequest.DestinationKey); IRequest request = new DefaultRequest(copyObjectRequest, "AmazonS3"); request.HttpMethod = "PUT"; if (copyObjectRequest.IsSetCannedACL()) { request.Headers.Add(HeaderKeys.XAmzAclHeader, S3Transforms.ToStringValue(copyObjectRequest.CannedACL)); } var headers = copyObjectRequest.Headers; foreach (var key in headers.Keys) { request.Headers[key] = headers[key]; } HeaderACLRequestMarshaller.Marshall(request, copyObjectRequest); if (copyObjectRequest.IsSetSourceBucket()) { request.Headers.Add(HeaderKeys.XAmzCopySourceHeader, ConstructCopySourceHeaderValue(copyObjectRequest.SourceBucket, sourceKey, copyObjectRequest.SourceVersionId)); } if (copyObjectRequest.IsSetETagToMatch()) { request.Headers.Add(HeaderKeys.XAmzCopySourceIfMatchHeader, S3Transforms.ToStringValue(copyObjectRequest.ETagToMatch)); } if (copyObjectRequest.IsSetModifiedSinceDateUtc()) { request.Headers.Add(HeaderKeys.XAmzCopySourceIfModifiedSinceHeader, S3Transforms.ToStringValue(copyObjectRequest.ModifiedSinceDateUtc)); } if (copyObjectRequest.IsSetETagToNotMatch()) { request.Headers.Add(HeaderKeys.XAmzCopySourceIfNoneMatchHeader, S3Transforms.ToStringValue(copyObjectRequest.ETagToNotMatch)); } if (copyObjectRequest.IsSetUnmodifiedSinceDateUtc()) { request.Headers.Add(HeaderKeys.XAmzCopySourceIfUnmodifiedSinceHeader, S3Transforms.ToStringValue(copyObjectRequest.UnmodifiedSinceDateUtc)); } if (copyObjectRequest.IsSetTagSet()) { request.Headers.Add(S3Constants.AmzHeaderTagging, AmazonS3Util.TagSetToQueryString(copyObjectRequest.TagSet)); request.Headers.Add(S3Constants.AmzHeaderTaggingDirective, TaggingDirective.REPLACE.Value); } else { request.Headers.Add(S3Constants.AmzHeaderTaggingDirective, TaggingDirective.COPY.Value); } request.Headers.Add(HeaderKeys.XAmzMetadataDirectiveHeader, S3Transforms.ToStringValue(copyObjectRequest.MetadataDirective.ToString())); if (copyObjectRequest.IsSetObjectLockLegalHoldStatus()) { request.Headers.Add("x-amz-object-lock-legal-hold", S3Transforms.ToStringValue(copyObjectRequest.ObjectLockLegalHoldStatus)); } if (copyObjectRequest.IsSetObjectLockMode()) { request.Headers.Add("x-amz-object-lock-mode", S3Transforms.ToStringValue(copyObjectRequest.ObjectLockMode)); } if (copyObjectRequest.IsSetObjectLockRetainUntilDate()) { request.Headers.Add("x-amz-object-lock-retain-until-date", S3Transforms.ToStringValue(copyObjectRequest.ObjectLockRetainUntilDate, AWSSDKUtils.ISO8601DateFormat)); } if (copyObjectRequest.IsSetServerSideEncryptionMethod()) { request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionHeader, S3Transforms.ToStringValue(copyObjectRequest.ServerSideEncryptionMethod)); } if (copyObjectRequest.IsSetServerSideEncryptionCustomerMethod()) { request.Headers.Add(HeaderKeys.XAmzSSECustomerAlgorithmHeader, copyObjectRequest.ServerSideEncryptionCustomerMethod); } if (copyObjectRequest.IsSetServerSideEncryptionCustomerProvidedKey()) { request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyHeader, copyObjectRequest.ServerSideEncryptionCustomerProvidedKey); if (copyObjectRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5()) { request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, copyObjectRequest.ServerSideEncryptionCustomerProvidedKeyMD5); } else { request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(copyObjectRequest.ServerSideEncryptionCustomerProvidedKey)); } } if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerMethod()) { request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerAlgorithmHeader, copyObjectRequest.CopySourceServerSideEncryptionCustomerMethod); } if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerProvidedKey()) { request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyHeader, copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKey); if (copyObjectRequest.IsSetCopySourceServerSideEncryptionCustomerProvidedKeyMD5()) { request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyMD5Header, copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKeyMD5); } else { request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(copyObjectRequest.CopySourceServerSideEncryptionCustomerProvidedKey)); } } if (copyObjectRequest.IsSetServerSideEncryptionKeyManagementServiceKeyId()) { request.Headers.Add(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader, copyObjectRequest.ServerSideEncryptionKeyManagementServiceKeyId); } if (copyObjectRequest.IsSetServerSideEncryptionKeyManagementServiceEncryptionContext()) { request.Headers.Add("x-amz-server-side-encryption-context", copyObjectRequest.ServerSideEncryptionKeyManagementServiceEncryptionContext); } if (copyObjectRequest.IsSetStorageClass()) { request.Headers.Add(HeaderKeys.XAmzStorageClassHeader, S3Transforms.ToStringValue(copyObjectRequest.StorageClass)); } if (copyObjectRequest.IsSetWebsiteRedirectLocation()) { request.Headers.Add(HeaderKeys.XAmzWebsiteRedirectLocationHeader, S3Transforms.ToStringValue(copyObjectRequest.WebsiteRedirectLocation)); } if (copyObjectRequest.IsSetRequestPayer()) { request.Headers.Add(S3Constants.AmzHeaderRequestPayer, S3Transforms.ToStringValue(copyObjectRequest.RequestPayer.ToString())); } if (copyObjectRequest.IsSetExpectedBucketOwner()) { request.Headers.Add(S3Constants.AmzHeaderExpectedBucketOwner, S3Transforms.ToStringValue(copyObjectRequest.ExpectedBucketOwner)); } if (copyObjectRequest.IsSetExpectedSourceBucketOwner()) { request.Headers.Add(S3Constants.AmzHeaderExpectedSourceBucketOwner, S3Transforms.ToStringValue(copyObjectRequest.ExpectedSourceBucketOwner)); } if (copyObjectRequest.IsSetBucketKeyEnabled()) { request.Headers.Add(S3Constants.AmzHeaderBucketKeyEnabled, S3Transforms.ToStringValue(copyObjectRequest.BucketKeyEnabled)); } AmazonS3Util.SetMetadataHeaders(request, copyObjectRequest.Metadata); if (string.IsNullOrEmpty(copyObjectRequest.DestinationBucket)) { throw new System.ArgumentException("DestinationBucket is a required property and must be set before making this call.", "CopyObjectRequest.DestinationBucket"); } if (string.IsNullOrEmpty(destinationKey)) { throw new System.ArgumentException("DestinationKey is a required property and must be set before making this call.", "CopyObjectRequest.DestinationKey"); } request.MarshallerVersion = 2; request.ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}", S3Transforms.ToStringValue(copyObjectRequest.DestinationBucket), S3Transforms.ToStringValue(destinationKey)); request.UseQueryString = true; return(request); }
public IRequest Marshall(CopyPartRequest copyPartRequest) { IRequest request = new DefaultRequest(copyPartRequest, "AmazonS3"); var sourceKey = AmazonS3Util.RemoveLeadingSlash(copyPartRequest.SourceKey); var destinationKey = AmazonS3Util.RemoveLeadingSlash(copyPartRequest.DestinationKey); request.HttpMethod = "PUT"; if (copyPartRequest.IsSetSourceBucket()) { request.Headers.Add(HeaderKeys.XAmzCopySourceHeader, ConstructCopySourceHeaderValue(copyPartRequest.SourceBucket, sourceKey, copyPartRequest.SourceVersionId)); } if (copyPartRequest.IsSetETagToMatch()) { request.Headers.Add(HeaderKeys.XAmzCopySourceIfMatchHeader, AWSSDKUtils.Join(copyPartRequest.ETagToMatch)); } if (copyPartRequest.IsSetETagToNotMatch()) { request.Headers.Add(HeaderKeys.XAmzCopySourceIfNoneMatchHeader, AWSSDKUtils.Join(copyPartRequest.ETagsToNotMatch)); } if (copyPartRequest.IsSetModifiedSinceDate()) { request.Headers.Add(HeaderKeys.XAmzCopySourceIfModifiedSinceHeader, copyPartRequest.ModifiedSinceDate.ToUniversalTime().ToString(AWSSDKUtils.GMTDateFormat, CultureInfo.InvariantCulture)); } if (copyPartRequest.IsSetUnmodifiedSinceDate()) { request.Headers.Add(HeaderKeys.XAmzCopySourceIfUnmodifiedSinceHeader, copyPartRequest.UnmodifiedSinceDate.ToUniversalTime().ToString(AWSSDKUtils.GMTDateFormat, CultureInfo.InvariantCulture)); } if (copyPartRequest.IsSetServerSideEncryptionCustomerMethod()) { request.Headers.Add(HeaderKeys.XAmzSSECustomerAlgorithmHeader, copyPartRequest.ServerSideEncryptionCustomerMethod); } if (copyPartRequest.IsSetServerSideEncryptionCustomerProvidedKey()) { request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyHeader, copyPartRequest.ServerSideEncryptionCustomerProvidedKey); if (copyPartRequest.IsSetServerSideEncryptionCustomerProvidedKeyMD5()) { request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, copyPartRequest.ServerSideEncryptionCustomerProvidedKeyMD5); } else { request.Headers.Add(HeaderKeys.XAmzSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(copyPartRequest.ServerSideEncryptionCustomerProvidedKey)); } } if (copyPartRequest.IsSetCopySourceServerSideEncryptionCustomerMethod()) { request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerAlgorithmHeader, copyPartRequest.CopySourceServerSideEncryptionCustomerMethod); } if (copyPartRequest.IsSetCopySourceServerSideEncryptionCustomerProvidedKey()) { request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyHeader, copyPartRequest.CopySourceServerSideEncryptionCustomerProvidedKey); if (copyPartRequest.IsSetCopySourceServerSideEncryptionCustomerProvidedKeyMD5()) { request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyMD5Header, copyPartRequest.CopySourceServerSideEncryptionCustomerProvidedKeyMD5); } else { request.Headers.Add(HeaderKeys.XAmzCopySourceSSECustomerKeyMD5Header, AmazonS3Util.ComputeEncodedMD5FromEncodedString(copyPartRequest.CopySourceServerSideEncryptionCustomerProvidedKey)); } } if (copyPartRequest.IsSetFirstByte() && copyPartRequest.IsSetLastByte()) { request.Headers.Add(HeaderKeys.XAmzCopySourceRangeHeader, ConstructCopySourceRangeHeader(copyPartRequest.FirstByte, copyPartRequest.LastByte)); } if (copyPartRequest.IsSetExpectedBucketOwner()) { request.Headers.Add(S3Constants.AmzHeaderExpectedBucketOwner, S3Transforms.ToStringValue(copyPartRequest.ExpectedBucketOwner)); } if (copyPartRequest.IsSetExpectedSourceBucketOwner()) { request.Headers.Add(S3Constants.AmzHeaderExpectedSourceBucketOwner, S3Transforms.ToStringValue(copyPartRequest.ExpectedSourceBucketOwner)); } if (string.IsNullOrEmpty(copyPartRequest.DestinationBucket)) { throw new System.ArgumentException("DestinationBucket is a required property and must be set before making this call.", "CopyPartRequest.DestinationBucket"); } if (string.IsNullOrEmpty(destinationKey)) { throw new System.ArgumentException("DestinationKey is a required property and must be set before making this call.", "CopyPartRequest.DestinationKey"); } request.MarshallerVersion = 2; request.ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}", S3Transforms.ToStringValue(copyPartRequest.DestinationBucket), S3Transforms.ToStringValue(destinationKey)); request.AddSubResource("partNumber", S3Transforms.ToStringValue(copyPartRequest.PartNumber)); request.AddSubResource("uploadId", S3Transforms.ToStringValue(copyPartRequest.UploadId)); request.UseQueryString = true; return(request); }