public static void Main(string[] args)
        {
            // create the ECS S3 Client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

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

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

            // get object metadata - not actual content (HEAD request not GET).
            GetObjectMetadataResponse response = s3.GetObjectMetadata(request);

            // print out object key/value and metadata key/value for validation
            Console.WriteLine(string.Format("Metadata for {0}/{1}", ECSS3Factory.S3_BUCKET, key));

            MetadataCollection metadataCollection = response.Metadata;

            ICollection <string> metaKeys = metadataCollection.Keys;

            foreach (string metaKey in metaKeys)
            {
                Console.WriteLine("{0}={1}", metaKey, metadataCollection[metaKey]);
            }
            Console.ReadLine();
        }
예제 #2
0
        public static void Main(string[] args)
        {
            // create the ECS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

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

            Console.Write("Enter the object content: ");
            string content = Console.ReadLine();

            // create object request with retrieved input
            PutObjectRequestECS request = new PutObjectRequestECS()
            {
                BucketName  = ECSS3Factory.S3_BUCKET,
                ContentBody = content,
                Key         = key
            };

            // create the object in demo bucket
            s3.PutObject(request);

            // print out object key/value for validation
            Console.WriteLine(string.Format("Created object {0}/{1} with content: {2}", ECSS3Factory.S3_BUCKET, key, content));
            Console.ReadLine();
        }
예제 #3
0
        public static void Main(string[] args)
        {
            // create the ECS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            // create bucket request
            PutBucketRequestECS request = new PutBucketRequestECS()
            {
                BucketName = ECSS3Factory.S3_BUCKET
            };

            // create bucket - used for subsequent demos
            s3.PutBucket(request);

            // create bucket lising request
            ListObjectsRequest objects = new ListObjectsRequest()
            {
                BucketName = ECSS3Factory.S3_BUCKET
            };

            // get bucket lising to retrieve bucket name
            ListObjectsResponse result = s3.ListObjects(objects);

            // print bucket name for validation
            Console.WriteLine(string.Format("Successfully created bucket {0}.", result.Name));
            Console.ReadLine();
        }
예제 #4
0
        public static void Main(string[] args)
        {
            // create the ECS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            // retrieve the object key and hours before expiration
            Console.Write("Enter the object key: ");
            string key = Console.ReadLine();

            Console.Write("How long should this tag be valid?: ");
            string hours = Console.ReadLine();

            // create expiration based on input
            DateTime expiration = DateTime.Now.AddHours(Convert.ToDouble(hours));

            // create the request object to generate pre-signed url
            GetPreSignedUrlRequest request = new GetPreSignedUrlRequest()
            {
                BucketName = ECSS3Factory.S3_BUCKET,
                Key        = key,
                Expires    = expiration,
                Verb       = HttpVerb.GET,
            };

            // get pre-signed url
            string url = s3.GetPreSignedURL(request);

            // print objects pre-signed url
            Console.WriteLine(string.Format("Object {0}/{1} pre-signed url: {2}", ECSS3Factory.S3_BUCKET, key, url));
            Console.ReadLine();
        }
예제 #5
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();
        }
예제 #6
0
        public static void Main(string[] args)
        {
            // create the AWS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

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

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

            // create the request object
            // When copying an object, you can preserve most of the metadata (default) or specify new metadata.
            // However, the ACL is not preserved and is set to private for the user making the request.
            CopyObjectRequest request = new CopyObjectRequest()
            {
                SourceBucket      = ECSS3Factory.S3_BUCKET,
                SourceKey         = key_source,
                DestinationBucket = ECSS3Factory.S3_BUCKET,
                DestinationKey    = key_target,
                MetadataDirective = S3MetadataDirective.COPY
            };

            // copy the object
            CopyObjectResponse response = s3.CopyObject(request);

            // print out object key/value for validation
            Console.WriteLine(string.Format("Copied object {0}/{1} to {2}/{3}", ECSS3Factory.S3_BUCKET, key_source, ECSS3Factory.S3_BUCKET, key_target));
            Console.ReadLine();
        }
예제 #7
0
        public static void Main(string[] args)
        {
            // create the AWS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            bool   moreRecords = true;
            string nextMarker  = string.Empty;

            while (moreRecords)
            {
                ListVersionsRequest request = new ListVersionsRequest()
                {
                    BucketName = ECSS3Factory.S3_BUCKET,
                };

                if (nextMarker.Length > 0)
                {
                    request.KeyMarker = nextMarker;
                }

                ListVersionsResponse response = new ListVersionsResponse();
                response = s3.ListVersions(request);


                foreach (S3ObjectVersion theObject in response.Versions)
                {
                    s3.DeleteObject(new DeleteObjectRequest()
                    {
                        BucketName = ECSS3Factory.S3_BUCKET,
                        Key        = theObject.Key,
                        VersionId  = theObject.VersionId
                    });
                    Console.WriteLine("Deleted {0}/{1}", ECSS3Factory.S3_BUCKET, theObject.Key);
                }

                Console.WriteLine(string.Format("Next Marker: {0} Version Count: {1}", response.NextKeyMarker, response.Versions.Count.ToString()));

                if (response.IsTruncated)
                {
                    nextMarker = response.NextKeyMarker;
                }
                else
                {
                    moreRecords = false;
                }
            }



            s3.DeleteBucket(new DeleteBucketRequest()
            {
                BucketName = ECSS3Factory.S3_BUCKET
            });

            // print bucket name for validation
            Console.WriteLine(string.Format("Deleted bucket {0}", ECSS3Factory.S3_BUCKET));
            Console.ReadLine();
        }
        private static async Task <PartETag> ProcessChunk(UploadPartRequest upr)
        {
            Console.WriteLine(string.Format("Sending chunk {0} starting at position {1}", upr.PartNumber, upr.FilePosition));

            // upload the chucnk and return a new PartETag when upload completes
            UploadPartResponse response = await ECSS3Factory.getS3Client().UploadPartAsync(upr, new System.Threading.CancellationToken());

            return(new PartETag(response.PartNumber, response.ETag));
        }
예제 #9
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();
        }
        public static void Main(string[] args)
        {
            // create the AWS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            // create the transfer utility using AWS S3 client
            TransferUtility fileTransferUtility = new TransferUtility(s3);

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

            Console.Write("Enter the file location: ");
            string filePath = Console.ReadLine();

            // configure transfer utility for parallel upload
            TransferUtilityUploadRequest uploadRequest = new TransferUtilityUploadRequest()
            {
                BucketName   = ECSS3Factory.S3_BUCKET,
                FilePath     = filePath,
                StorageClass = S3StorageClass.Standard,
                PartSize     = 1024 * 1024 * 8, // 8MB
                Key          = key
            };

            // grab the start time of upload
            DateTime startDate = DateTime.Now;

            // upload the file
            fileTransferUtility.Upload(uploadRequest);

            // grab the end time of upload
            DateTime endDate = DateTime.Now;

            Console.WriteLine(string.Format("Completed multi-part upload for object {0}/{1} with file path: {2}", ECSS3Factory.S3_BUCKET, key, filePath));
            Console.WriteLine(string.Format("Process took: {0} seconds.", (endDate - startDate).TotalSeconds.ToString()));

            Console.ReadLine();
        }
예제 #11
0
        public static void Main(string[] args)
        {
            // create the ECS S3 Client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

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

            Console.Write("Enter the object content: ");
            string content = Console.ReadLine();

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

            Console.Write("Enter the metadata value: ");
            string metaValue = Console.ReadLine();

            // create object request with retrieved input
            PutObjectRequestECS request = new PutObjectRequestECS()
            {
                BucketName  = ECSS3Factory.S3_BUCKET,
                ContentBody = content,
                Key         = key
            };

            // add metadata to request
            request.Metadata.Add(metaKey, metaValue);

            // create the object with metadata in the demo bucket
            s3.PutObject(request);

            // print out object key/value and metadata key/value for validation
            Console.WriteLine(string.Format("Create object {0}/{1} with metadata {2}={3} and content: {4}",
                                            ECSS3Factory.S3_BUCKET, key, metaKey, metaValue, content));
            Console.ReadLine();
        }
예제 #12
0
        public static void Main(string[] args)
        {
            // create the ECS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

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

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

            // delete the object in the demo bucket
            s3.DeleteObject(request);


            // print out object key/value for validation
            Console.WriteLine(string.Format("Object {0}/{1} deleted", ECSS3Factory.S3_BUCKET, key));
            Console.ReadLine();
        }
예제 #13
0
        public static void Main(string[] args)
        {
            // create the AWS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            foreach (string key in KEY_LIST)
            {
                // create object request with retrieved input
                PutObjectRequest request = new PutObjectRequest()
                {
                    BucketName  = ECSS3Factory.S3_BUCKET,
                    ContentBody = key,
                    Key         = key
                };

                // create the object in demo bucket
                s3.PutObject(request);
            }


            while (true)
            {
                Console.Write("Enter the prefix (empty if none): ");
                string prefix = Console.ReadLine();
                Console.Write("Enter the delimiter (e.g. /, empty for none): ");
                string delimiter = Console.ReadLine();
                Console.Write("Enter the marker (empty if none): ");
                string marker = Console.ReadLine();
                Console.Write("Enter the max keys (empty for defaul): ");
                string maxKeys = Console.ReadLine();

                ListObjectsRequest request = new ListObjectsRequest()
                {
                    BucketName = ECSS3Factory.S3_BUCKET
                };

                if (prefix.Length > 0)
                {
                    request.Prefix = prefix;
                }

                if (delimiter.Length > 0)
                {
                    request.Delimiter = delimiter;
                }

                if (marker.Length > 0)
                {
                    request.Marker = marker;
                }

                if (maxKeys.Length > 0)
                {
                    request.MaxKeys = Int32.Parse(maxKeys);
                }

                ListObjectsResponse response = s3.ListObjects(request);

                Console.WriteLine("-----------------");
                Console.WriteLine("Bucket: " + ECSS3Factory.S3_BUCKET);
                Console.WriteLine("Prefix: " + response.Prefix);
                Console.WriteLine("Delimiter: " + response.Delimiter);
                Console.WriteLine("Marker: " + marker);
                Console.WriteLine("IsTruncated? " + response.IsTruncated);
                Console.WriteLine("NextMarker: " + response.NextMarker);

                Console.WriteLine();

                if (response.CommonPrefixes != null)
                {
                    foreach (string commonPrefix in response.CommonPrefixes)
                    {
                        Console.WriteLine("CommonPrefix: " + commonPrefix);
                    }
                }

                Console.WriteLine("Printing objects");
                Console.WriteLine("-----------------");


                foreach (S3Object s3Object in response.S3Objects)
                {
                    Console.WriteLine(String.Format("{0}    {1}     {2}", s3Object.LastModified.ToString(), s3Object.Size, s3Object.Key));
                }

                Console.Write("Another? (Y/N) ");
                string another = Console.ReadLine();

                if (another.ToUpper() == "N")
                {
                    break;
                }
            }

            foreach (string key in KEY_LIST)
            {
                s3.DeleteObject(ECSS3Factory.S3_BUCKET, key);
            }

            Console.ReadLine();
        }
        public static void Main(string[] args)
        {
            ECSS3Client         s3 = ECSS3Factory.getS3Client();
            PutObjectRequestECS request;

            string key        = "update-append.txt";               // object key to create, update, and append
            string bucketName = ECSS3Factory.S3_BUCKET;            // bucket to create object in
            string content    = "The tan fox jumped over the dog"; // initial object content
            int    tanIndex   = content.IndexOf("tan");

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

            // first create an initial object
            request             = new PutObjectRequestECS();
            request.BucketName  = bucketName;
            request.Key         = key;
            request.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)));

            // update the object in the middle
            string content2 = "red";

            request             = new PutObjectRequestECS();
            request.BucketName  = bucketName;
            request.Key         = key;
            request.ContentBody = content2;
            request.Range       = Range.fromOffsetLength(tanIndex, content2.Length);
            Console.WriteLine(string.Format("updating object at offset {0}", tanIndex));
            s3.PutObject(request);

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

            // append to the object
            string content3 = " and cat";

            Console.WriteLine(string.Format("appending object at offset {0}", content.Length));
            request             = new PutObjectRequestECS();
            request.BucketName  = bucketName;
            request.Key         = key;
            request.ContentBody = content3;
            request.Range       = Range.fromOffset(content.Length);
            s3.PutObject(request);

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

            // create a sparse object by appending past the end of the object
            string content4 = "#last byte#";

            Console.WriteLine(string.Format("sparse append object at offset {0}", 45));
            request             = new PutObjectRequestECS();
            request.BucketName  = bucketName;
            request.Key         = key;
            request.ContentBody = content4;
            request.Range       = Range.fromOffset(45);
            s3.PutObject(request);

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

            Console.ReadLine();
        }
        public static async Task MainSync(string key, string filePath)
        {
            // create the AWS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            // part size for chunking in multi-part
            long partSize = 1024 * 1024 * 8; // 8 MB

            // list of upload part response objects for each part that is uploaded
            IEnumerable <PartETag> partETags = new List <PartETag>();

            // Step 1: Initialize
            InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest()
            {
                BucketName = ECSS3Factory.S3_BUCKET,
                Key        = key,
            };

            // call initialize method -obtain upload id to be used for subsequent parts.
            InitiateMultipartUploadResponse initResponse = s3.InitiateMultipartUpload(initRequest);

            // get the file and file length
            fileSize = new FileInfo(filePath).Length;

            Console.WriteLine(string.Format("Starting multi-part upload for object {0}/{1} with file path {2} and size {3} in {4} MB size chunks",
                                            ECSS3Factory.S3_BUCKET, key, filePath, Convert.ToString(fileSize), partSize / 1024 / 1024));

            try
            {
                // STEP 2: generate list of parts to be uploaded
                long filePosition = 0;

                // the parts list representing each chunk to be uploaded
                List <UploadPartRequest> parts = new List <UploadPartRequest>();

                for (int i = 1; filePosition < fileSize; i++)
                {
                    // get the size of the chunk. Note - the last part can be less than the chunk size
                    partSize = Math.Min(partSize, (fileSize - filePosition));

                    // create request to upload  a part
                    UploadPartRequest uploadRequest = new UploadPartRequest()
                    {
                        BucketName   = ECSS3Factory.S3_BUCKET,
                        Key          = key,
                        UploadId     = initResponse.UploadId,
                        PartNumber   = i,
                        FilePosition = filePosition,
                        FilePath     = filePath,
                        PartSize     = partSize
                    };

                    parts.Add(uploadRequest);

                    filePosition = filePosition += partSize;
                }

                // generate query to simultaneously upload chunks
                IEnumerable <Task <PartETag> > uploadTasksQuery =
                    from part in parts select ProcessChunk(part);

                // execute the upload query
                List <Task <PartETag> > uploadTasks = uploadTasksQuery.ToList();

                //
                // Can do other work here while waiting ...
                Console.WriteLine("Waiting for completion of multi-part upload");
                //
                //

                // wait here for the query to complete
                partETags = await Task.WhenAll(uploadTasks);

                // STEP 3: complete the mpu
                CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest()
                {
                    BucketName = ECSS3Factory.S3_BUCKET,
                    Key        = key,
                    UploadId   = initResponse.UploadId,
                    PartETags  = partETags.ToList()
                };

                s3.CompleteMultipartUpload(compRequest);
            }
            catch (Exception e)
            {
                s3.AbortMultipartUpload(new AbortMultipartUploadRequest()
                {
                    BucketName = ECSS3Factory.S3_BUCKET,
                    Key        = key,
                    UploadId   = initResponse.UploadId
                });

                Console.WriteLine(e);
            }
        }
예제 #16
0
        public static void Main(string[] args)
        {
            // create the ECS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            // Create the bucket with indexed keys
            List <MetaSearchKey> bucketMetadataSearchKeys = new List <MetaSearchKey>()
            {
                new MetaSearchKey()
                {
                    Name = USER_PREFIX + FIELD_ACCOUNT_ID, Type = MetaSearchDatatype.integer
                },
                new MetaSearchKey()
                {
                    Name = USER_PREFIX + FIELD_BILLING_DATE, Type = MetaSearchDatatype.datetime
                },
                new MetaSearchKey()
                {
                    Name = USER_PREFIX + FIELD_BILL_TYPE, Type = MetaSearchDatatype.@string
                }
            };


            PutBucketRequestECS pbr = new PutBucketRequestECS();

            pbr.BucketName = BUCKET_NAME;
            pbr.SetMetadataSearchKeys(bucketMetadataSearchKeys);
            s3.PutBucket(pbr);

            foreach (string key in KEY_LIST)
            {
                PutObjectRequestECS por = new PutObjectRequestECS();
                por.BucketName = BUCKET_NAME;
                por.Key        = key;
                por.Metadata.Add(FIELD_ACCOUNT_ID, extractAccountId(key));
                por.Metadata.Add(FIELD_BILLING_DATE, extractBillDate(key));
                por.Metadata.Add(FIELD_BILL_TYPE, extractBillType(key));
                s3.PutObject(por);
            }

            while (true)
            {
                Console.Write("Enter the account id (empty for none): ");
                string accountId = Console.ReadLine();
                Console.Write("Enter the billing date (e.g. 2016-09-22, empty for none): ");
                string billingDate = Console.ReadLine();
                Console.Write("Enter the bill type (e.g. xml.  empty for none): ");
                string billType = Console.ReadLine();

                QueryObjectsRequest qor = new QueryObjectsRequest()
                {
                    BucketName = BUCKET_NAME
                };

                StringBuilder query = new StringBuilder();
                if (accountId.Length > 0)
                {
                    query.Append(USER_PREFIX + FIELD_ACCOUNT_ID + "==" + accountId + "");
                }

                if (billingDate.Length > 0)
                {
                    if (query.Length > 0)
                    {
                        query.Append(" and ");
                    }
                    query.Append(USER_PREFIX + FIELD_BILLING_DATE + "==" + billingDate + "T00:00:00Z");
                }

                if (billType.Length > 0)
                {
                    if (query.Length > 0)
                    {
                        query.Append(" and ");
                    }
                    query.Append(USER_PREFIX + FIELD_BILL_TYPE + "=='" + billType + "'");
                }

                qor.Query = query.ToString();

                QueryObjectsResponse res = s3.QueryObjects(qor);
                Console.WriteLine("--------------------------");
                Console.WriteLine("Bucket: " + res.BucketName);
                Console.WriteLine("Query: " + qor.Query);
                Console.WriteLine();

                Console.WriteLine("Key");
                Console.WriteLine("--------------------------");

                foreach (QueryObject obj in res.ObjectMatches)
                {
                    Console.WriteLine(string.Format("{0}", obj.Name));
                }

                Console.Write("Another? (Y/N) ");
                string another = Console.ReadLine();

                if (another.ToUpper() == "N")
                {
                    break;
                }
            }

            //cleanup
            foreach (string key in KEY_LIST)
            {
                s3.DeleteObject(BUCKET_NAME, key);
            }
            s3.DeleteBucket(BUCKET_NAME);
        }
예제 #17
0
        public static void Main(string[] args)
        {
            // create the ECS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

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

            Console.Write("Enter the file location: ");
            string filePath = Console.ReadLine();

            // grab the start time of upload
            DateTime startDate = DateTime.Now;

            // part size for chunking in multi-part
            long partSize = 1024 * 1024 * 8; // 2 MB

            // list of upload part response objects for each part that is uploaded
            List <PartETag> partETags = new List <PartETag>();

            // Step 1: Initialize
            InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest()
            {
                BucketName = ECSS3Factory.S3_BUCKET,
                Key        = key,
            };

            InitiateMultipartUploadResponse initResponse = s3.InitiateMultipartUpload(initRequest);

            // get the file and file length
            long contentLength = new FileInfo(filePath).Length;

            Console.WriteLine(string.Format("Starting multi-part upload for object {0}/{1} with file path {2} and size {3} in {4} MB size chunks",
                                            ECSS3Factory.S3_BUCKET, key, filePath, Convert.ToString(contentLength), partSize / 1024 / 1024));

            try
            {
                // Step 2: Upload parts
                long filePosition = 0;
                for (int i = 1; filePosition < contentLength; i++)
                {
                    // get the size of the chunk. Note - the last part can be less than the chunk size
                    partSize = Math.Min(partSize, (contentLength - filePosition));

                    Console.WriteLine(string.Format("Sending chunk {0} starting at position {1}", i, filePosition));

                    // create request to upload  a part
                    UploadPartRequest uploadRequest = new UploadPartRequest()
                    {
                        BucketName   = ECSS3Factory.S3_BUCKET,
                        Key          = key,
                        UploadId     = initResponse.UploadId,
                        PartNumber   = i,
                        FilePosition = filePosition,
                        FilePath     = filePath,
                        PartSize     = partSize
                    };

                    UploadPartResponse partResponse = s3.UploadPart(uploadRequest);
                    PartETag           eTagPart     = new PartETag(partResponse.PartNumber, partResponse.ETag);
                    partETags.Add(eTagPart);

                    filePosition = filePosition += partSize;
                }

                // Step 3: complete
                Console.WriteLine("Waiting for completion of multi-part upload");
                CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest()
                {
                    BucketName = ECSS3Factory.S3_BUCKET,
                    Key        = key,
                    UploadId   = initResponse.UploadId,
                    PartETags  = partETags
                };

                s3.CompleteMultipartUpload(compRequest);
            }
            catch (Exception e)
            {
                s3.AbortMultipartUpload(new AbortMultipartUploadRequest()
                {
                    BucketName = ECSS3Factory.S3_BUCKET,
                    Key        = key,
                    UploadId   = initResponse.UploadId
                });

                Console.WriteLine(e);
            }

            // grab the end time of upload
            DateTime endDate = DateTime.Now;

            Console.WriteLine(string.Format("Completed multi-part upload for object {0}/{1} with file path: {2}", ECSS3Factory.S3_BUCKET, key, filePath));
            Console.WriteLine(string.Format("Process took: {0} seconds.", (endDate - startDate).TotalSeconds.ToString()));
            Console.ReadLine();
        }