AWSSDK.IntegrationTests.S3.S3TestUtils.GetObjectHelper C# (CSharp) Method

GetObjectHelper() public static method

public static GetObjectHelper ( AmazonS3Client client, string bucketName, string key ) : GetObjectResponse
client Amazon.S3.AmazonS3Client
bucketName string
key string
return Amazon.S3.Model.GetObjectResponse
        public static GetObjectResponse GetObjectHelper(AmazonS3Client client, string bucketName, string key)
        {
            GetObjectResponse r = null;
            Exception responseException = null;
            AutoResetEvent ars = new AutoResetEvent(false);

            client.GetObjectAsync(new GetObjectRequest()
            {
                BucketName = bucketName,
                Key = key
            }, (response) =>
            {
                responseException = response.Exception;
                if (responseException == null)
                {
                    r = response.Response;
                }
                ars.Set();
            }, new AsyncOptions { ExecuteCallbackOnMainThread = false });
            ars.WaitOne();

            if (responseException != null)
            {
                throw responseException;
            }
            return r;
        }

Usage Example

        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));
        }
All Usage Examples Of AWSSDK.IntegrationTests.S3.S3TestUtils::GetObjectHelper