private static void TestGetS3Object(string fileName) { Console.WriteLine("========================================================"); Console.WriteLine("| Testing Get S3 File |"); Console.WriteLine("========================================================"); // Create new utility instance DocumentUploadUtility utility = new DocumentUploadUtility(DefaultBucket, AccessKey, SecretKey); try { TestDocumentEntity document = utility.GetTestDocument(TestUser, fileName, DefaultBucket); Console.WriteLine("Document found ..."); Console.WriteLine("File Name: " + document.FileName); Console.WriteLine("Owner: " + document.Owner); Console.WriteLine("File contents:"); Console.WriteLine(document.Contents); } catch (Exception ex) { Console.WriteLine("An error occured ..."); Console.WriteLine("Message: " + ex.Message); Console.WriteLine("StackTrace:\n" + ex.StackTrace); } Console.WriteLine(); }
private static void TestUpdateS3Object(string filename) { Console.WriteLine("========================================================"); Console.WriteLine("| Testing Update S3 File |"); Console.WriteLine("========================================================"); // Create new utility instance DocumentUploadUtility utility = new DocumentUploadUtility(DefaultBucket, AccessKey, SecretKey); try { TestDocumentEntity document = utility.GetTestDocument(TestUser, filename, DefaultBucket); DocumentEntity entity = null; using (FileStream stream = File.Create(filename)) { string newLine = "\nThis is a new line for update " + DateTime.Now.ToString(); stream.BeginWrite(Encoding.ASCII.GetBytes(document.Contents + newLine), 0, Encoding.ASCII.GetByteCount(document.Contents + newLine), null, null); DocumentProcessor processor = new DocumentProcessor(User, DefaultBucket, AccessKey, SecretKey); entity = processor.UploadDocument(filename, "txt", stream); } if (entity != null) { Console.WriteLine("Successfully updated file in S3: "); Console.WriteLine("Document Name: " + entity.FileName); Console.WriteLine("Document Created: " + entity.CreateDate.ToString()); Console.WriteLine("Document Last Updated: " + entity.LastUpdateDate.ToString()); } } catch (Exception ex) { Console.WriteLine("An error occured ..."); Console.WriteLine("Message: " + ex.Message); Console.WriteLine("StackTrace:\n" + ex.StackTrace); } File.Delete(filename); Console.WriteLine(); }