コード例 #1
0
        public void TestAppendObject()
        {
            string key     = "key-1";
            string content = "What goes up";

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

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

            // append to the object
            long result = client.AppendObject(temp_bucket, key, " must come down.");

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

            Assert.AreEqual("What goes up must come down.", readContent);
            Assert.AreEqual(content.Length, result);
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            // create the ECS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            // object key to create, update, and append
            string key        = "atomic-append.txt";
            string bucketName = ECSS3Factory.S3_BUCKET; // bucket to create object in
            string content    = "Hello World!";

            // first create an initial object
            Console.WriteLine(string.Format("creating initial object {0}/{1} with content: {2}", ECSS3Factory.S3_BUCKET, key, content));

            PutObjectRequestECS request = new PutObjectRequestECS()
            {
                BucketName  = bucketName,
                Key         = key,
                ContentBody = content
            };

            s3.PutObject(request);

            // read object and print content
            Console.WriteLine(string.Format("initial object {0}/{1} with content: [{2}]", bucketName, key, readObject(s3, bucketName, key)));

            // append to the end of the object
            string content2 = " ... and Universe!!";

            // the offset at which our appended data was written is returned
            // (this is the previous size of the object)
            long appendOffset = s3.AppendObject(bucketName, key, content2);

            Console.WriteLine(string.Format("append successful at offset {0}", appendOffset));

            // read object and print content
            Console.WriteLine(string.Format("final object {0}/{1} with content: [{2}]", bucketName, key, readObject(s3, bucketName, key)));

            Console.ReadLine();
        }