public void TestUpdateObjectWithRange()
        {
            string key     = "key-1";
            string content = "The cat crossed the road.";
            int    offset  = content.IndexOf("cat");

            PutObjectRequestECS por = new PutObjectRequestECS()
            {
                BucketName  = temp_bucket,
                Key         = key,
                ContentBody = content
            };

            // create the object
            client.PutObject(por);

            string updatePart = "dog";

            por = new PutObjectRequestECS()
            {
                BucketName  = temp_bucket,
                Key         = key,
                Range       = Range.fromOffsetLength(offset, updatePart.Length),
                ContentBody = updatePart
            };

            // update the object
            client.PutObject(por);

            // verify update
            GetObjectResponse response       = client.GetObject(temp_bucket, key);
            Stream            responseStream = response.ResponseStream;
            StreamReader      reader         = new StreamReader(responseStream);
            string            readContent    = reader.ReadToEnd();

            Assert.AreEqual("The dog crossed the road.", readContent);

            updatePart = "very lucky animal crossed the road.";

            por = new PutObjectRequestECS()
            {
                BucketName  = temp_bucket,
                Key         = key,
                Range       = Range.fromOffset(offset),
                ContentBody = updatePart
            };

            client.PutObject(por);

            // verify update
            response       = client.GetObject(temp_bucket, key);
            responseStream = response.ResponseStream;
            reader         = new StreamReader(responseStream);
            readContent    = reader.ReadToEnd();
            Assert.AreEqual(content.Substring(0, offset) + updatePart, readContent);
        }
예제 #2
0
        public static void Main(string[] args)
        {
            // create the ECS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            // retrieve the key value from user
            Console.Write("Enter the object key: ");
            string key = Console.ReadLine();

            // create the request object
            GetObjectRequest request = new GetObjectRequest()
            {
                BucketName = ECSS3Factory.S3_BUCKET,
                Key        = key,
            };

            // read the object from the demo bucket
            GetObjectResponse response = s3.GetObject(request);

            // convert the object to a text string
            Stream       responseStream = response.ResponseStream;
            StreamReader reader         = new StreamReader(responseStream);
            string       content        = reader.ReadToEnd();

            // print object key/value and content for validation
            Console.WriteLine(string.Format("Object {0} contents: {1}", response.Key, content));
            Console.ReadLine();
        }
        private static string readObject(ECSS3Client s3, string bucketName, string key)
        {
            GetObjectResponse response       = s3.GetObject(bucketName, key);
            Stream            responseStream = response.ResponseStream;
            StreamReader      reader         = new StreamReader(responseStream);

            return(reader.ReadToEnd());
        }