PostObjectHelper() публичный статический Метод

public static PostObjectHelper ( AmazonS3Client client, string bucketName, string key, PostObjectRequestManipulator manipulator = null ) : PostObjectResponse
client Amazon.S3.AmazonS3Client
bucketName string
key string
manipulator PostObjectRequestManipulator
Результат Amazon.S3.Model.PostObjectResponse
Пример #1
0
        public void TestPostCannedACLInner()
        {
            var key = string.Format(FileNameFormat, DateTime.Now.Ticks);

            // Authenticated Read
            S3TestUtils.PostObjectHelper(Client, BucketName, key, delegate(PostObjectRequest request) { request.CannedACL = S3CannedACL.AuthenticatedRead; });
            var grants = S3TestUtils.GetACLHelper(Client, BucketName, key).AccessControlList.Grants;

            Utils.AssertTrue(GrantsContain(grants, AuthenticatedUsersUriSubstring, S3Permission.READ));
            Utils.AssertTrue(GrantsDoNotContain(grants, AllUsersUriSubstring));
            Utils.AssertTrue(GrantsDoNotContain(grants, LogDeliveryUriSubstring));

            // No canned ACL equivalent to Private
            S3TestUtils.PostObjectHelper(Client, BucketName, key);
            grants = S3TestUtils.GetACLHelper(Client, BucketName, key).AccessControlList.Grants;
            Utils.AssertTrue(GrantsDoNotContain(grants, AuthenticatedUsersUriSubstring));
            Utils.AssertTrue(GrantsDoNotContain(grants, AllUsersUriSubstring));
            Utils.AssertTrue(GrantsDoNotContain(grants, LogDeliveryUriSubstring));

            // Private
            S3TestUtils.PostObjectHelper(Client, BucketName, key, delegate(PostObjectRequest request) { request.CannedACL = S3CannedACL.Private; });
            grants = S3TestUtils.GetACLHelper(Client, BucketName, key).AccessControlList.Grants;
            Utils.AssertTrue(GrantsDoNotContain(grants, AuthenticatedUsersUriSubstring));
            Utils.AssertTrue(GrantsDoNotContain(grants, AllUsersUriSubstring));
            Utils.AssertTrue(GrantsDoNotContain(grants, LogDeliveryUriSubstring));

            S3TestUtils.DeleteObjectHelper(Client, BucketName, key);
        }
Пример #2
0
        private void HeadersPostTestInner()
        {
            var contentType        = "image/jpeg";
            var cacheControl       = "private";
            var contentEncoding    = "deflate";
            var contentDisposition = "attachment; filename=f.gz";
            var key     = string.Format(FileNameFormat, DateTime.Now.Ticks);
            var expires = DateTime.Now.AddDays(1);

            S3TestUtils.PostObjectHelper(Client, BucketName, key, delegate(PostObjectRequest request)
            {
                request.Headers.ContentType        = contentType;
                request.Headers.CacheControl       = cacheControl;
                request.Headers.ContentEncoding    = contentEncoding;
                request.Headers.ContentDisposition = contentDisposition;
                request.Headers.Expires            = expires;
            });
            var gotten = S3TestUtils.GetObjectHelper(Client, BucketName, key);

            Utils.AssertTrue(string.Compare(gotten.Headers.ContentType, contentType, true) == 0);
            Utils.AssertTrue(string.Compare(gotten.Headers.CacheControl, cacheControl, true) == 0);
            Utils.AssertTrue(string.Compare(gotten.Headers.ContentDisposition, contentDisposition, true) == 0);
            Utils.AssertTrue(string.Compare(gotten.Headers.ContentEncoding, contentEncoding, true) == 0);
            // strip precision before comparing dates
            Utils.AssertTrue(gotten.Expires.ToString(Amazon.Util.AWSSDKUtils.ISO8601BasicDateTimeFormat) == expires.ToString(Amazon.Util.AWSSDKUtils.ISO8601BasicDateTimeFormat));
        }
Пример #3
0
 public void TestHttpErrorPostResponseUnmarshalling()
 {
     try
     {
         S3TestUtils.PostObjectHelper(Client, "NonExistentBucket" + DateTime.Now.Ticks, "key");
     }
     catch (Amazon.Runtime.Internal.HttpErrorResponseException exception)
     {
         Assert.AreEqual(HttpStatusCode.Forbidden, exception.Response.StatusCode);
         return;
     };
     Assert.Fail();
 }
Пример #4
0
        public void TestPostObjectVersioning()
        {
            var key      = "Key";
            var response = S3TestUtils.PostObjectHelper(Client, VersionedBucketName, key);
            var version1 = response.VersionId;

            Utils.AssertFalse(string.IsNullOrEmpty(version1));
            response = S3TestUtils.PostObjectHelper(Client, VersionedBucketName, key);
            var version2 = response.VersionId;

            Utils.AssertFalse(string.IsNullOrEmpty(version2));
            Utils.AssertTrue(version1 != version2);
            response = S3TestUtils.PostObjectHelper(Client, VersionedBucketName, key);
            var version3 = response.VersionId;

            Utils.AssertFalse(string.IsNullOrEmpty(version3));
            Utils.AssertTrue(version1 != version3);
            Utils.AssertTrue(version2 != version3);
        }
Пример #5
0
        private void SimplePostTestInner()
        {
            AutoResetEvent ars = new AutoResetEvent(false);
            Exception      responseException = new Exception();
            VersionStatus  status            = null;

            Client.GetBucketVersioningAsync(new GetBucketVersioningRequest()
            {
                BucketName = BucketName
            }, (response) =>
            {
                responseException = response.Exception;
                if (responseException == null)
                {
                    status = response.Response.VersioningConfig.Status;
                }
                ars.Set();
            }, new AsyncOptions {
                ExecuteCallbackOnMainThread = false
            });
            ars.WaitOne();
            Assert.IsNull(responseException);
            Assert.AreEqual(VersionStatus.Off, status);
            List <S3Object> s3Objects = S3TestUtils.ListObjectsHelper(Client, BucketName);

            Assert.IsNotNull(s3Objects);
            var count = s3Objects.Count;

            var key = string.Format(FileNameFormat, DateTime.Now.Ticks);

            S3TestUtils.PostObjectHelper(Client, BucketName, key);

            s3Objects = S3TestUtils.ListObjectsHelper(Client, BucketName);
            Assert.IsNotNull(s3Objects);
            Assert.AreEqual(count + 1, s3Objects.Count);

            S3TestUtils.DeleteObjectHelper(Client, BucketName, key);

            s3Objects = S3TestUtils.ListObjectsHelper(Client, BucketName);
            Assert.IsNotNull(s3Objects);
            Assert.AreEqual(count, s3Objects.Count);
        }
Пример #6
0
        public void TestSingleUploads()
        {
            // Test simple PostObject upload
            var objectKey = "contentbodyput" + DateTime.Now.Ticks;

            S3TestUtils.PostObjectHelper(Client, BucketName, objectKey, SetMetadata);
            var response = S3TestUtils.GetObjectHelper(Client, BucketName, objectKey);

            S3TestUtils.DeleteObjectHelper(Client, BucketName, objectKey);

            var prefixLen = "x-amz-meta-".Length;

            foreach (var fullKey in response.Metadata.Keys)
            {
                // remove x-amz-meta-, ignoring case
                var shortKey      = fullKey.StartsWith("x-amz-meta-", StringComparison.OrdinalIgnoreCase) ? fullKey.Substring(prefixLen, fullKey.Length - prefixLen) : fullKey;
                var actualValue   = response.Metadata[fullKey];
                var expectedValue = Metadata[shortKey];
                Assert.AreEqual(expectedValue, actualValue);
            }
        }
Пример #7
0
        public void PostObjectKMSTest()
        {
            string originalSigV = Client.Config.SignatureVersion;

            try
            {
                // KMS only allowed for sigv4
                Client.Config.SignatureVersion = "4";

                var key = string.Format(FileNameFormat, DateTime.Now.Ticks);
                S3TestUtils.PostObjectHelper(Client, BucketName, key, (request) =>
                {
                    request.Headers[HeaderKeys.XAmzServerSideEncryptionHeader] = ServerSideEncryptionMethod.AWSKMS;
                });

                AutoResetEvent ars = new AutoResetEvent(false);
                Exception      responseException = new Exception();
                string         objectContent     = null;
                Client.GetObjectAsync(BucketName, key, (response) =>
                {
                    responseException = response.Exception;
                    if (responseException == null)
                    {
                        using (var reader = new StreamReader(response.Response.ResponseStream))
                        {
                            objectContent = reader.ReadToEnd();
                        }
                    }
                    ars.Set();
                });

                ars.WaitOne();
                Assert.IsNull(responseException);
                Utils.AssertTrue(S3TestUtils.TestContent == objectContent, string.Format("{0} != {1}", S3TestUtils.TestContent, objectContent));
            }
            finally
            {
                Client.Config.SignatureVersion = originalSigV;
            }
        }