Esempio n. 1
0
        // Get object in a bucket
        public async static Task Run(MinioClient minio,
                                     string bucketName = "my-bucket-name",
                                     string objectName = "my-object-name",
                                     string fileName   = "my-file-name")
        {
            try
            {
                Console.WriteLine("Running example for API: SelectObjectContentAsync");

                QueryExpressionType queryType = QueryExpressionType.SQL;
                string queryExpr = "select count(*) from s3object";
                SelectObjectInputSerialization inputSerialization = new SelectObjectInputSerialization()
                {
                    CompressionType = SelectCompressionType.NONE,
                    CSV             = new CSVInputOptions()
                    {
                        FileHeaderInfo  = CSVFileHeaderInfo.None,
                        RecordDelimiter = "\n",
                        FieldDelimiter  = ",",
                    }
                };
                SelectObjectOutputSerialization outputSerialization = new SelectObjectOutputSerialization()
                {
                    CSV = new CSVOutputOptions()
                    {
                        RecordDelimiter = "\n",
                        FieldDelimiter  = ",",
                    }
                };
                SelectObjectContentArgs args = new SelectObjectContentArgs()
                                               .WithBucket(bucketName)
                                               .WithObject(objectName)
                                               .WithExpressionType(queryType)
                                               .WithQueryExpression(queryExpr)
                                               .WithInputSerialization(inputSerialization)
                                               .WithOutputSerialization(outputSerialization);
                SelectResponseStream resp = await minio.SelectObjectContentAsync(args);

                resp.Payload.CopyTo(Console.OpenStandardOutput());
                Console.WriteLine("Bytes scanned:" + resp.Stats.BytesScanned);
                Console.WriteLine("Bytes returned:" + resp.Stats.BytesReturned);
                Console.WriteLine("Bytes processed:" + resp.Stats.BytesProcessed);
                if (resp.Progress != null)
                {
                    Console.WriteLine("Progress :" + resp.Progress.BytesProcessed);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Bucket]  Exception: {e}");
            }
        }
        // Get object in a bucket
        public async static Task Run(MinioClient minio,
                                     string bucketName = "my-bucket-name",
                                     string objectName = "my-object-name",
                                     string fileName   = "my-file-name")
        {
            string newObjectName = "new" + objectName;

            try
            {
                Console.WriteLine("Running example for API: SelectObjectContentAsync");

                StringBuilder csvString = new StringBuilder();
                csvString.AppendLine("Employee,Manager,Group");
                csvString.AppendLine("Employee4,Employee2,500");
                csvString.AppendLine("Employee3,Employee1,500");
                csvString.AppendLine("Employee1,,1000");
                csvString.AppendLine("Employee5,Employee1,500");
                csvString.AppendLine("Employee2,Employee1,800");
                var csvBytes = Encoding.UTF8.GetBytes(csvString.ToString());
                using (var stream = new MemoryStream(csvBytes))
                {
                    PutObjectArgs putObjectArgs = new PutObjectArgs()
                                                  .WithBucket(bucketName)
                                                  .WithObject(newObjectName)
                                                  .WithStreamData(stream)
                                                  .WithObjectSize(stream.Length);
                    await minio.PutObjectAsync(putObjectArgs);
                }
                QueryExpressionType queryType = QueryExpressionType.SQL;
                string queryExpr = "select count(*) from s3object";
                SelectObjectInputSerialization inputSerialization = new SelectObjectInputSerialization()
                {
                    CompressionType = SelectCompressionType.NONE,
                    CSV             = new CSVInputOptions()
                    {
                        FileHeaderInfo  = CSVFileHeaderInfo.None,
                        RecordDelimiter = "\n",
                        FieldDelimiter  = ",",
                    }
                };
                SelectObjectOutputSerialization outputSerialization = new SelectObjectOutputSerialization()
                {
                    CSV = new CSVOutputOptions()
                    {
                        RecordDelimiter = "\n",
                        FieldDelimiter  = ",",
                    }
                };
                SelectObjectContentArgs args = new SelectObjectContentArgs()
                                               .WithBucket(bucketName)
                                               .WithObject(newObjectName)
                                               .WithExpressionType(queryType)
                                               .WithQueryExpression(queryExpr)
                                               .WithInputSerialization(inputSerialization)
                                               .WithOutputSerialization(outputSerialization);
                SelectResponseStream resp = await minio.SelectObjectContentAsync(args);

                resp.Payload.CopyTo(Console.OpenStandardOutput());
                Console.WriteLine("Bytes scanned:" + resp.Stats.BytesScanned);
                Console.WriteLine("Bytes returned:" + resp.Stats.BytesReturned);
                Console.WriteLine("Bytes processed:" + resp.Stats.BytesProcessed);
                if (resp.Progress != null)
                {
                    Console.WriteLine("Progress :" + resp.Progress.BytesProcessed);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Bucket]  Exception: {e}");
            }
        }
 internal SelectObjectContentResponse(HttpStatusCode statusCode, string responseContent, byte[] responseRawBytes)
     : base(statusCode, responseContent)
 {
     this.ResponseStream = new SelectResponseStream(new MemoryStream(responseRawBytes));
 }