Exemple #1
0
        /// <summary>
        /// Marshall PutObjectTaggingRequest into an http request.
        /// </summary>
        public IRequest Marshall(PutObjectTaggingRequest putObjectTaggingRequest)
        {
            IRequest request = new DefaultRequest(putObjectTaggingRequest, "AmazonS3");

            request.HttpMethod = "PUT";

            request.ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}",
                                                 S3Transforms.ToStringValue(putObjectTaggingRequest.BucketName),
                                                 S3Transforms.ToStringValue(putObjectTaggingRequest.Key));
            request.AddSubResource("tagging");

            if (putObjectTaggingRequest.IsSetVersionId())
            {
                request.AddSubResource("versionId", putObjectTaggingRequest.VersionId);
            }

            try
            {
                var content = AmazonS3Util.SerializeTaggingToXml(putObjectTaggingRequest.Tagging);
                request.Content = Encoding.UTF8.GetBytes(content);
                request.Headers[HeaderKeys.ContentTypeHeader] = "application/xml";

                var checksum = AmazonS3Util.GenerateChecksumForContent(content, true);
                request.Headers[HeaderKeys.ContentMD5Header] = checksum;
            }
            catch (EncoderFallbackException e)
            {
                throw new AmazonServiceException("Unable to marhsall request to XML", e);
            }

            return(request);
        }
Exemple #2
0
        /// <summary>
        /// Marshall PutObjectTaggingRequest into an http request.
        /// </summary>
        public IRequest Marshall(PutObjectTaggingRequest putObjectTaggingRequest)
        {
            IRequest request = new DefaultRequest(putObjectTaggingRequest, "AmazonS3");

            request.HttpMethod = "PUT";

            if (putObjectTaggingRequest.IsSetChecksumAlgorithm())
            {
                request.Headers.Add(S3Constants.AmzHeaderSdkChecksumAlgorithm, S3Transforms.ToStringValue(putObjectTaggingRequest.ChecksumAlgorithm));
            }
            if (putObjectTaggingRequest.IsSetExpectedBucketOwner())
            {
                request.Headers.Add(S3Constants.AmzHeaderExpectedBucketOwner, S3Transforms.ToStringValue(putObjectTaggingRequest.ExpectedBucketOwner));
            }
            if (putObjectTaggingRequest.IsSetRequestPayer())
            {
                request.Headers.Add(S3Constants.AmzHeaderRequestPayer, S3Transforms.ToStringValue(putObjectTaggingRequest.RequestPayer));
            }

            if (string.IsNullOrEmpty(putObjectTaggingRequest.BucketName))
            {
                throw new System.ArgumentException("BucketName is a required property and must be set before making this call.", "PutObjectTaggingRequest.BucketName");
            }
            if (string.IsNullOrEmpty(putObjectTaggingRequest.Key))
            {
                throw new System.ArgumentException("Key is a required property and must be set before making this call.", "PutObjectTaggingRequest.Key");
            }

            request.ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}/{1}",
                                                 S3Transforms.ToStringValue(putObjectTaggingRequest.BucketName),
                                                 S3Transforms.ToStringValue(putObjectTaggingRequest.Key));
            request.AddSubResource("tagging");

            if (putObjectTaggingRequest.IsSetVersionId())
            {
                request.AddSubResource("versionId", putObjectTaggingRequest.VersionId);
            }

            try
            {
                var content = AmazonS3Util.SerializeTaggingToXml(putObjectTaggingRequest.Tagging);
                request.Content = Encoding.UTF8.GetBytes(content);
                request.Headers[HeaderKeys.ContentTypeHeader] = "application/xml";

                ChecksumUtils.SetRequestChecksum(request, putObjectTaggingRequest.ChecksumAlgorithm);
            }
            catch (EncoderFallbackException e)
            {
                throw new AmazonServiceException("Unable to marhsall request to XML", e);
            }

            return(request);
        }
        public IRequest Marshall(PutObjectTaggingRequest putObjectTaggingRequest)
        {
            //IL_0006: Unknown result type (might be due to invalid IL or missing references)
            //IL_000c: Expected O, but got Unknown
            //IL_00ad: Unknown result type (might be due to invalid IL or missing references)
            IRequest val = new DefaultRequest(putObjectTaggingRequest, "AmazonS3");

            val.set_HttpMethod("PUT");
            val.set_ResourcePath(string.Format(CultureInfo.InvariantCulture, "/{0}/{1}", S3Transforms.ToStringValue(putObjectTaggingRequest.BucketName), S3Transforms.ToStringValue(putObjectTaggingRequest.Key)));
            val.AddSubResource("tagging");
            try
            {
                string text = AmazonS3Util.SerializeTaggingToXml(putObjectTaggingRequest.Tagging);
                val.set_Content(Encoding.UTF8.GetBytes(text));
                val.get_Headers()["Content-Type"] = "application/xml";
                string value = AmazonS3Util.GenerateChecksumForContent(text, fBase64Encode: true);
                val.get_Headers()["Content-MD5"] = value;
                return(val);
            }
            catch (EncoderFallbackException ex)
            {
                throw new AmazonServiceException("Unable to marhsall request to XML", (Exception)ex);
            }
        }