AWSSDK.IntegrationTests.S3.S3TestUtils.PostObjectHelper C# (CSharp) Метод

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
        public static PostObjectResponse PostObjectHelper(AmazonS3Client client, string bucketName, string key, PostObjectRequestManipulator manipulator = null)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                PostObjectResponse r = null;
                Exception responseException = null;
                StreamWriter writer = new StreamWriter(stream);
                writer.Write(TestContent);
                writer.Flush();
                stream.Position = 0;
                AutoResetEvent ars = new AutoResetEvent(false);
                var request = new PostObjectRequest()
                {
                    Bucket = bucketName,
                    Key = key,
                    InputStream = stream
                };
                if (manipulator != null)
                {
                    manipulator(request);
                }
                client.PostObjectAsync(request, (response) =>
                {
                    responseException = response.Exception;
                    if (responseException == null)
                    {
                        r = response.Response;
                    }
                    else
                    {
                        Debug.LogWarning(new StreamReader((responseException as Amazon.Runtime.Internal.HttpErrorResponseException).Response.ResponseBody.OpenResponse()).ReadToEnd());
                    }
                    ars.Set();
                }, new AsyncOptions { ExecuteCallbackOnMainThread = false });
                ars.WaitOne();
                if (responseException != null)
                {
                    throw responseException;
                }
                return r;
            }
        }

Usage Example

Пример #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);
        }
All Usage Examples Of AWSSDK.IntegrationTests.S3.S3TestUtils::PostObjectHelper