Example #1
0
        public async Task PresignedGetObjectWithHeaders()
        {
            var client = new MinioClient()
                         .WithEndpoint("localhost", 9001)
                         .WithCredentials("my-access-key", "my-secret-key")
                         .Build();

            Mock <IRestClient> restClient = MockRestClient(client.restClient.BaseUrl);

            client.restClient = restClient.Object;

            Dictionary <string, string> reqParams = new Dictionary <string, string>
            {
                { "Response-Content-Disposition", "attachment; filename=\"filename.jpg\"" },
            };
            PresignedGetObjectArgs presignedGetArgs = new PresignedGetObjectArgs()
                                                      .WithBucket("bucket")
                                                      .WithObject("object-name")
                                                      .WithExpiry(3600)
                                                      .WithRequestDate(_requestDate)
                                                      .WithHeaders(reqParams);
            var signedUrl = await client.PresignedGetObjectAsync(presignedGetArgs);

            Assert.IsTrue(signedUrl.Equals("http://localhost:9001/bucket/object-name?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=my-access-key%2F20200501%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200501T154533Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3D%22filename.jpg%22&X-Amz-Signature=33e766c15afc36558d37e995b5997d16def98a0aa622f0b518811eafcb60b910"));
        }
Example #2
0
        public async Task PresignedGetObjectWithHeaders()
        {
            // todo how to test this with mock client.
            var client = new MinioClient()
                         .WithEndpoint("play.min.io")
                         .WithCredentials("Q3AM3UQ867SPQQA43P2F",
                                          "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

            var bucket     = "bucket";
            var objectName = "object-name";

            Dictionary <string, string> reqParams = new Dictionary <string, string>
            {
                { "Response-Content-Disposition", "attachment; filename=\"filename.jpg\"" },
            };

            var bktExistArgs = new BucketExistsArgs()
                               .WithBucket(bucket);
            bool found = await client.BucketExistsAsync(bktExistArgs);

            if (!found)
            {
                var mkBktArgs = new MakeBucketArgs()
                                .WithBucket(bucket);
                await client.MakeBucketAsync(mkBktArgs);
            }

            if (!await this.ObjectExistsAsync(client, bucket, objectName))
            {
                var helloData   = Encoding.UTF8.GetBytes("hello world");
                var helloStream = new MemoryStream();
                helloStream.Write(helloData);
                var PutObjectArgs = new PutObjectArgs()
                                    .WithBucket(bucket)
                                    .WithObject(objectName)
                                    .WithStreamData(helloStream)
                                    .WithObjectSize(helloData.Length);
                await client.PutObjectAsync(PutObjectArgs);
            }

            PresignedGetObjectArgs presignedGetObjectArgs = new PresignedGetObjectArgs()
                                                            .WithBucket("bucket")
                                                            .WithObject("object-name")
                                                            .WithExpiry(3600)
                                                            .WithHeaders(reqParams)
                                                            .WithRequestDate(_requestDate);

            var signedUrl = client.PresignedGetObjectAsync(presignedGetObjectArgs);

            Assert.AreEqual(
                "http://play.min.io/bucket/object-name?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=Q3AM3UQ867SPQQA43P2F%2F20200501%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200501T154533Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3D%22filename.jpg%22&X-Amz-Signature=de66f04dd4ac35838b9e83d669f7b5a70b452c6468e2b4a9e9c29f42e7fa102d",
                signedUrl);
        }
Example #3
0
 public async static Task Run(MinioClient client,
                              string bucketName = "my-bucket-name",
                              string objectName = "my-object-name")
 {
     var reqParams = new Dictionary <string, string> {
         { "response-content-type", "application/json" }
     };
     PresignedGetObjectArgs args = new PresignedGetObjectArgs()
                                   .WithBucket(bucketName)
                                   .WithObject(objectName)
                                   .WithExpiry(1000)
                                   .WithHeaders(reqParams);
     var presignedUrl = await client.PresignedGetObjectAsync(args);
 }
Example #4
0
        public async Task PresignedGetObject()
        {
            // todo how to test this with mock client.
            var client = new MinioClient()
                         .WithEndpoint("play.min.io")
                         .WithCredentials("Q3AM3UQ867SPQQA43P2F",
                                          "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

            var bucket     = "bucket";
            var objectName = "object-name";

            var bktExistArgs = new BucketExistsArgs()
                               .WithBucket(bucket);
            bool found = await client.BucketExistsAsync(bktExistArgs);

            if (!found)
            {
                var mkBktArgs = new MakeBucketArgs()
                                .WithBucket(bucket);
                await client.MakeBucketAsync(mkBktArgs);
            }

            if (!await this.ObjectExistsAsync(client, bucket, objectName))
            {
                var helloData   = Encoding.UTF8.GetBytes("hello world");
                var helloStream = new MemoryStream();
                helloStream.Write(helloData);
                helloStream.Seek(0, SeekOrigin.Begin);
                var PutObjectArgs = new PutObjectArgs()
                                    .WithBucket(bucket)
                                    .WithObject(objectName)
                                    .WithStreamData(helloStream)
                                    .WithObjectSize(helloData.Length);
                await client.PutObjectAsync(PutObjectArgs);
            }

            PresignedGetObjectArgs presignedGetObjectArgs = new PresignedGetObjectArgs()
                                                            .WithBucket("bucket")
                                                            .WithObject("object-name")
                                                            .WithExpiry(3600)
                                                            .WithRequestDate(_requestDate);

            var signedUrl = client.PresignedGetObjectAsync(presignedGetObjectArgs);

            Assert.AreEqual(
                "http://play.min.io/bucket/object-name?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=Q3AM3UQ867SPQQA43P2F%2F20200501%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200501T154533Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=d4202da690618f77142d6f0557c97839f0773b2c718082e745cd9b199aa6b28f",
                signedUrl);
        }
Example #5
0
        public async Task PresignedGetObject()
        {
            var client = new MinioClient()
                         .WithCredentials("my-access-key", "my-secret-key")
                         .WithEndpoint("localhost", 9001)
                         .Build();

            Mock <IRestClient> restClient = MockRestClient(client.restClient.BaseUrl);

            client.restClient = restClient.Object;

            PresignedGetObjectArgs presignedGetArgs = new PresignedGetObjectArgs()
                                                      .WithBucket("bucket")
                                                      .WithObject("object-name")
                                                      .WithExpiry(3600)
                                                      .WithRequestDate(_requestDate);
            var signedUrl = await client.PresignedGetObjectAsync(presignedGetArgs);

            Assert.AreEqual(
                "http://localhost:9001/bucket/object-name?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=my-access-key%2F20200501%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200501T154533Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=6dfd01cd302737c58c80e9ca1ec4abaa34e85d9ab3156d5704ea7b88bc9bdd37",
                signedUrl);
        }
        public async static Task Run(MinioClient client,
                                     string bucketName = "my-bucket-name",
                                     string objectName = "my-object-name")
        {
            try
            {
                var reqParams = new Dictionary <string, string> {
                    { "response-content-type", "application/json" }
                };
                PresignedGetObjectArgs args = new PresignedGetObjectArgs()
                                              .WithBucket(bucketName)
                                              .WithObject(objectName)
                                              .WithExpiry(1000)
                                              .WithHeaders(reqParams);
                string presignedUrl = await client.PresignedGetObjectAsync(args);

                Console.WriteLine(presignedUrl);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception {e.Message}");
            }
        }