Amazon.S3.Util.AmazonS3Util.SetWebsiteRedirectLocation C# (CSharp) Method

SetWebsiteRedirectLocation() public static method

Sets the redirect location for the S3 Object's when being accessed through the S3 website endpoint.
public static SetWebsiteRedirectLocation ( IAmazonS3 s3Client, string bucketName, string key, string websiteRedirectLocation ) : void
s3Client IAmazonS3 The Amazon S3 Client to use for S3 specific operations.
bucketName string The name of the bucket in which the key is stored
key string The key of the S3 Object
websiteRedirectLocation string The redirect location
return void
        public static void SetWebsiteRedirectLocation(IAmazonS3 s3Client, string bucketName, string key, string websiteRedirectLocation)
        {
            CopyObjectRequest copyRequest;
            PutACLRequest putACLRequest;

            SetupForObjectModification(s3Client, bucketName, key, null, out copyRequest, out putACLRequest);

            copyRequest.WebsiteRedirectLocation = websiteRedirectLocation;
            CopyObjectResponse copyResponse = s3Client.CopyObject(copyRequest);

            if (!string.IsNullOrEmpty(copyResponse.SourceVersionId))
                putACLRequest.VersionId = copyResponse.SourceVersionId;

            s3Client.PutACL(putACLRequest);
        }