Example #1
0
        public async Task HeadObject()
        {
            await UploadAsync(nameof(HeadObject)).ConfigureAwait(false);

            HeadObjectResponse gResp = await ObjectClient.HeadObjectAsync(BucketName, nameof(HeadObject)).ConfigureAwait(false);

            Assert.Equal(200, gResp.StatusCode);
        }
Example #2
0
        public async Task HeadObjectWebsiteRedirect()
        {
            await UploadAsync(nameof(HeadObjectWebsiteRedirect), request => request.WebsiteRedirectLocation = "https://google.com").ConfigureAwait(false);

            HeadObjectResponse resp1 = await ObjectClient.HeadObjectAsync(BucketName, nameof(HeadObjectWebsiteRedirect)).ConfigureAwait(false);

            Assert.Equal("https://google.com", resp1.WebsiteRedirectLocation);
            Assert.Equal(200, resp1.StatusCode);
        }
Example #3
0
        public async Task HeadObjectContentRange()
        {
            await UploadAsync(nameof(HeadObjectContentRange)).ConfigureAwait(false);

            HeadObjectResponse headResp = await ObjectClient.HeadObjectAsync(BucketName, nameof(HeadObjectContentRange), req => req.Range.Add(0, 2)).ConfigureAwait(false);

            Assert.Equal("bytes", headResp.AcceptRanges);
            Assert.Equal("bytes 0-2/4", headResp.ContentRange);
        }
Example #4
0
        public async Task HeadObjectMultipleTags()
        {
            await UploadAsync(nameof(HeadObjectMultipleTags), request =>
            {
                request.Tags.Add("mykey1", "myvalue1");
                request.Tags.Add("mykey2", "myvalue2");
            }).ConfigureAwait(false);

            HeadObjectResponse gResp = await ObjectClient.HeadObjectAsync(BucketName, nameof(HeadObjectMultipleTags)).ConfigureAwait(false);

            Assert.Equal(2, gResp.TagCount);
        }
Example #5
0
        public async Task HeadObjectLifecycle()
        {
            PutObjectResponse putResp = await UploadAsync(nameof(HeadObjectLifecycle)).ConfigureAwait(false);

            Assert.Equal(200, putResp.StatusCode);

            HeadObjectResponse headResp = await ObjectClient.HeadObjectAsync(BucketName, nameof(HeadObjectLifecycle)).ConfigureAwait(false);

            //Expiration should work on head too
            Assert.Equal(DateTime.UtcNow.AddDays(2).Date, headResp.LifeCycleExpiresOn !.Value.UtcDateTime.Date);
            Assert.Equal("ExpireAll", headResp.LifeCycleRuleId);
        }
Example #6
0
        public async Task PutObjectLegalHold()
        {
            await UploadAsync(nameof(PutObjectLegalHold), req => req.LockLegalHold = true).ConfigureAwait(false);

            GetObjectResponse getResp = await AssertAsync(nameof(PutObjectLegalHold)).ConfigureAwait(false);

            Assert.True(getResp.LockLegalHold);

            HeadObjectResponse headResp = await ObjectClient.HeadObjectAsync(BucketName, nameof(PutObjectLegalHold)).ConfigureAwait(false);

            Assert.True(headResp.LockLegalHold);
        }
Example #7
0
        public async Task HeadObjectResponseHeaders()
        {
            //Upload a file for tests
            await UploadAsync(nameof(HeadObjectResponseHeaders)).ConfigureAwait(false);

            HeadObjectResponse response = await ObjectClient.HeadObjectAsync(BucketName, nameof(HeadObjectResponseHeaders), request =>
            {
                request.ResponseCacheControl.Set(CacheControlType.MaxAge, 42);
                request.ResponseContentDisposition.Set(ContentDispositionType.Attachment, "filename.txt");
                request.ResponseContentEncoding.Add(ContentEncodingType.Gzip);
                request.ResponseContentLanguage.Add("da-DK");
                request.ResponseContentType.Set("text/html", "utf-8");
                request.ResponseExpires = DateTimeOffset.UtcNow;
            }).ConfigureAwait(false);

            Assert.Equal("max-age=42", response.CacheControl);
            Assert.Equal("attachment; filename=\"filename.txt\"", response.ContentDisposition);
            Assert.Equal("da-DK", response.ContentLanguage);
            Assert.Equal("text/html; charset=utf-8", response.ContentType);
            Assert.Equal(DateTime.UtcNow, response.ExpiresOn !.Value.DateTime, TimeSpan.FromSeconds(5));
        }
Example #8
0
        public async Task MultipartViaClient()
        {
            byte[] data = new byte[10 * 1024 * 1024]; //10 Mb

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)(i % 255);
            }

            using (MemoryStream ms = new MemoryStream(data))
            {
                MultipartUploadStatus resp = await MultipartClient.MultipartUploadAsync(BucketName, nameof(MultipartViaClient), ms, 5 * 1024 * 1024).ConfigureAwait(false);

                Assert.Equal(MultipartUploadStatus.Ok, resp);
            }

            GetObjectResponse getResp = await ObjectClient.GetObjectAsync(BucketName, nameof(MultipartViaClient)).ConfigureAwait(false);

            Assert.True(getResp.IsSuccess);

            using (MemoryStream ms = new MemoryStream())
            {
                await getResp.Content.CopyToAsync(ms).ConfigureAwait(false);

                Assert.Equal(data, ms.ToArray());
            }

            //Try multipart downloading it
            using (MemoryStream ms = new MemoryStream())
            {
                await MultipartClient.MultipartDownloadAsync(BucketName, nameof(MultipartViaClient), ms).ConfigureAwait(false);

                Assert.Equal(data, ms.ToArray());
            }

            HeadObjectResponse headResp = await ObjectClient.HeadObjectAsync(BucketName, nameof(MultipartViaClient), req => req.PartNumber = 1).ConfigureAwait(false);

            Assert.Equal(2, headResp.NumberOfParts);
        }
Example #9
0
        public async Task MultipartFluid()
        {
            byte[] data = new byte[10 * 1024 * 1024]; //10 Mb

            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)(i % 255);
            }

            MultipartUploadStatus resp = await Transfer.UploadData(BucketName, nameof(MultipartFluid), data)
                                         .ExecuteMultipartAsync()
                                         .ConfigureAwait(false);

            Assert.Equal(MultipartUploadStatus.Ok, resp);

            GetObjectResponse getResp = await ObjectClient.GetObjectAsync(BucketName, nameof(MultipartViaClient)).ConfigureAwait(false);

            Assert.True(getResp.IsSuccess);

            using (MemoryStream ms = new MemoryStream())
            {
                await getResp.Content.CopyToAsync(ms).ConfigureAwait(false);

                Assert.Equal(data, ms.ToArray());
            }

            //TODO: Need Download Transfer support first
            //Try multipart downloading it
            //using (MemoryStream ms = new MemoryStream())
            //{
            //    await ObjectClient.MultipartDownloadAsync(BucketName, nameof(MultipartViaClient), ms).ConfigureAwait(false);
            //    Assert.Equal(data, ms.ToArray());
            //}

            HeadObjectResponse headResp = await ObjectClient.HeadObjectAsync(BucketName, nameof(MultipartViaClient), req => req.PartNumber = 1).ConfigureAwait(false);

            Assert.Equal(2, headResp.NumberOfParts);
        }