Ejemplo n.º 1
0
        /// 检索对象内容
        public void SelectObject()
        {
            //.cssg-snippet-body-start:[select-object]
            try
            {
                string bucket = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID
                string key    = "exampleobject";            //对象键

                SelectObjectRequest request = new SelectObjectRequest(bucket, key);

                ObjectSelectionFormat.JSONFormat jSONFormat = new ObjectSelectionFormat.JSONFormat();
                jSONFormat.Type            = "DOCUMENT";
                jSONFormat.RecordDelimiter = "\n";

                string outputFile = "select_local_file.json";

                request.setExpression("Select * from COSObject")
                .setInputFormat(new ObjectSelectionFormat(null, jSONFormat))
                .setOutputFormat(new ObjectSelectionFormat(null, jSONFormat))
                .SetCosProgressCallback(delegate(long progress, long total) {
                    Console.WriteLine("OnProgress : " + progress + "," + total);
                })
                .outputToFile(outputFile)
                ;

                SelectObjectResult selectObjectResult = cosXml.selectObject(request);
                Console.WriteLine(selectObjectResult.stat);
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.StackTrace);
                Console.WriteLine("CosClientException: " + clientEx.Message);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
            }
            //.cssg-snippet-body-end
        }