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
Example #1
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));
        }
Example #2
0
        private void GzipPostTestInner()
        {
            var contentType     = "application/x-gzip";
            var contentEncoding = "gzip";
            var key             = string.Format(GzipFileNameFormat, DateTime.Now.Ticks);

            AutoResetEvent ars = new AutoResetEvent(false);

            Exception responseException = new Exception();
            string    fileName          = string.Format(GzipFileNameFormat, DateTime.Now.Ticks);
            TextAsset gzippedFile       = null;

            byte[] buffer = null;
            UnityRequestQueue.Instance.ExecuteOnMainThread(() =>
            {
                gzippedFile = Resources.Load("gzipFile") as TextAsset;
                buffer      = gzippedFile.bytes;
                ars.Set();
            });

            ars.WaitOne();

            var memoryStream = new MemoryStream(buffer);

            var request = new PostObjectRequest()
            {
                Key         = fileName,
                Bucket      = BucketName,
                InputStream = memoryStream,
                CannedACL   = S3CannedACL.Private
            };

            request.Headers.ContentEncoding = contentEncoding;
            request.Headers.ContentType     = contentType;

            Client.PostObjectAsync(request, (response) =>
            {
                responseException = response.Exception;
                ars.Set();
            }, new AsyncOptions {
                ExecuteCallbackOnMainThread = true
            });

            ars.WaitOne();
            Assert.IsNull(responseException);

            var gotten = S3TestUtils.GetObjectHelper(Client, BucketName, fileName);

            Utils.AssertTrue(string.Compare(gotten.Headers.ContentType, contentType, true) == 0, string.Format("content types: {0} != {1}", gotten.Headers.ContentType, contentType));
            // Unity removes the Content-Encoding header after unzipping :(.
            //Utils.AssertTrue(string.Compare(gotten.Headers.ContentEncoding, contentEncoding, true) == 0);
        }
Example #3
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);
            }
        }