public void UploadFile(Uri fileUrl, Stream s)
        {
            var filePath = fileUrl.AbsolutePath;
            // We need to strip off any leading '/' in the path or
            // else it creates a path with an empty leading segment
            if (filePath.StartsWith("/"))
                filePath = filePath.Substring(1);

            var s3 = new Amazon.S3.AmazonS3Client(
                    AccessKeyId, SecretAccessKey, RegionEndpoint);

            var s3Requ = new Amazon.S3.Model.PutObjectRequest
            {
                BucketName = BucketName,
                Key = filePath,
                InputStream = s,
                AutoCloseStream = false,
            };
            var s3Resp = s3.PutObject(s3Requ);

            if (DnsProvider != null)
            {
                var hostname = fileUrl.Host;
                DnsProvider.EditCnameRecord(hostname, DnsCnameTarget);
            }
            else
            {
                // TODO:  do nothing for now
                // Throw Exception???
            }
        }
예제 #2
0
        public void UploadFile(Uri fileUrl, Stream s)
        {
            var filePath = fileUrl.AbsolutePath;

            // We need to strip off any leading '/' in the path or
            // else it creates a path with an empty leading segment
            if (filePath.StartsWith("/"))
            {
                filePath = filePath.Substring(1);
            }

            var s3 = new Amazon.S3.AmazonS3Client(
                AccessKeyId, SecretAccessKey, RegionEndpoint);

            var s3Requ = new Amazon.S3.Model.PutObjectRequest
            {
                BucketName      = BucketName,
                Key             = filePath,
                InputStream     = s,
                AutoCloseStream = false,
            };
            var s3Resp = s3.PutObject(s3Requ);

            if (DnsProvider != null)
            {
                var hostname = fileUrl.Host;
                DnsProvider.EditCnameRecord(hostname, DnsCnameTarget);
            }
            else
            {
                // TODO:  do nothing for now
                // Throw Exception???
            }
        }
예제 #3
0
        public void Execute(JobExecutionContext context)
        {
            //Get Current Batch
            //Close Current Batch
            //And Open New One
            //Create a new BatchFile Record
            logger.Log(LogLevel.Info, String.Format("Creating Nacha ACH File at {0}", System.DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")));

            logger.Log(LogLevel.Info, String.Format("Batching Transactions"));
            var transactions = transactionBatchService.BatchTransactions();

            FileGenerator fileGeneratorService = new FileGenerator();

            fileGeneratorService.CompanyIdentificationNumber = ConfigurationManager.AppSettings["CompanyIdentificationNumber"];
            fileGeneratorService.CompanyName                     = ConfigurationManager.AppSettings["CompanyName"];
            fileGeneratorService.ImmediateDestinationId          = ConfigurationManager.AppSettings["ImmediateDestinationId"];
            fileGeneratorService.ImmediateDestinationName        = ConfigurationManager.AppSettings["ImmediateDestinationName"];
            fileGeneratorService.ImmediateOriginId               = ConfigurationManager.AppSettings["ImmediateOriginId"];
            fileGeneratorService.ImmediateOriginName             = ConfigurationManager.AppSettings["ImmediateOriginName"];
            fileGeneratorService.OriginatingTransitRoutingNumber = ConfigurationManager.AppSettings["OriginatingTransitRoutingNumber"];
            fileGeneratorService.CompanyDiscretionaryData        = ConfigurationManager.AppSettings["CompanyDiscretionaryData"];

            logger.Log(LogLevel.Info, String.Format("Processing Transactions"));

            var results = fileGeneratorService.ProcessFile(transactions);

            logger.Log(LogLevel.Info, String.Format("Creating Batch File"));

            StringBuilder sb = new StringBuilder();

            results.ForEach(s => sb.AppendLine(s));
            string fileContext = sb.ToString();

            logger.Log(LogLevel.Info, String.Format("Uploading Batch File to S3 Server"));

            string bucketName = ConfigurationManager.AppSettings["NachaFileBucketName"];

            if (String.IsNullOrEmpty(bucketName))
            {
                throw new Exception("S3 bucket name for NachaFileBucketName not configured");
            }

            Amazon.S3.AmazonS3Client s3Client   = new Amazon.S3.AmazonS3Client();
            PutObjectRequest         putRequest = new PutObjectRequest()
            {
                ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256,
                BucketName  = bucketName,
                ContentBody = fileContext,
                Key         = "NACHA_FILE_" + System.DateTime.Now.ToString("MMddyy_Hmmss")
            };

            s3Client.PutObject(putRequest);

            //Move all payments to paid
            //Update Batch File
            //Start BatchFile Workflow
        }
예제 #4
0
        public void CrudCalls()
        {
            var originalBuilds = GetAllBuilds().ToList();

            var timestamp = DateTime.Now.ToFileTime().ToString();
            var newBuild  = Client.CreateBuild(new CreateBuildRequest
            {
                Name    = "TestBuild-" + timestamp,
                Version = timestamp
            }).Build;

            createdBuilds.Add(newBuild.BuildId);

            var builds = GetAllBuilds().ToList();

            Assert.AreNotEqual(originalBuilds.Count, builds.Count);

            Client.UpdateBuild(new UpdateBuildRequest
            {
                BuildId = newBuild.BuildId,
                Name    = newBuild.Name + "_2",
                Version = newBuild.Version + "_2"
            });

            var uploadCreds     = Client.RequestUploadCredentials(newBuild.BuildId);
            var storageLocation = uploadCreds.StorageLocation;
            var credentials     = uploadCreds.UploadCredentials;

            using (var s3client = new Amazon.S3.AmazonS3Client(credentials))
            {
                var putResponse = s3client.PutObject(new Amazon.S3.Model.PutObjectRequest
                {
                    BucketName  = storageLocation.Bucket,
                    Key         = storageLocation.Key,
                    ContentBody = "test content"
                });
                Console.WriteLine(putResponse.ContentLength);
            }

            Client.DeleteBuild(newBuild.BuildId);
            createdBuilds.Remove(newBuild.BuildId);

            builds = GetAllBuilds().ToList();
            Assert.AreEqual(originalBuilds.Count, builds.Count);
        }
예제 #5
0
        /// <summary>
        //
        /// </summary>
        /// <param name="siteId"></param>
        /// <param name="fileName">should be unique id: 234234546.jpg or
        ///     /images/34234234234.pjg
        /// </param>
        /// <param name="content"></param>
        /// <param name="contentType"></param>
        /// <returns>Returns the URL address of the file...</returns>
        public string Upload(string filePath, System.IO.Stream fileStream, string contentType)
        {
            Amazon.S3.AmazonS3Config config = new Amazon.S3.AmazonS3Config().
                                              WithCommunicationProtocol(Protocol.HTTP);

            string key = filePath.Replace(BaseURL, "");

            Amazon.S3.AmazonS3Client client = new Amazon.S3.AmazonS3Client(ConfigurationLibrary.Config.fileAmazonS3AccessKey,
                                                                           ConfigurationLibrary.Config.fileAmazonS3SecreyKey, config);
            //System.IO.MemoryStream stream = new System.IO.MemoryStream(content);

            try
            {
                PutObjectRequest request = new PutObjectRequest();
                request.WithInputStream(fileStream);
                request.WithBucketName(BucketName);
                request.WithKey(key);
                request.WithCannedACL(S3CannedACL.PublicRead);

                S3Response response = client.PutObject(request);
                //response.Dispose();
            }
            catch (Amazon.S3.AmazonS3Exception ex)
            {
                if (ex.ErrorCode != null && (ex.ErrorCode.Equals("InvalidAccessKeyId") || ex.ErrorCode.Equals("InvalidSecurity")))
                {
                    Console.WriteLine("Please check the provided AWS Credentials.");
                    Console.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
                }
                else
                {
                    Console.WriteLine("An error occurred with the message '{0}' when writing an object", ex.Message);
                }
            }
            client.Dispose();

            //SetACL(fileName, true);

            string fileUrl = BaseURL + key;

            return(fileUrl);
        }
예제 #6
0
        public override Result Execute(ConDepSettings settings, CancellationToken token)
        {
            var dynamicAwsConfig = settings.Config.OperationsConfig.Aws;
            var fileName         = Path.GetFileName(_srcFile);

            var client     = new Amazon.S3.AmazonS3Client(GetAwsCredentials(dynamicAwsConfig), RegionEndpoint.GetBySystemName((string)dynamicAwsConfig.Region));
            var objRequest = new PutObjectRequest
            {
                BucketName = _bucket,
                Key        =
                    string.IsNullOrWhiteSpace(_options.Values.TargetFolderPath)
                        ? fileName
                        : Path.Combine(_options.Values.TargetFolderPath, fileName).Replace('\\', '/'),
                FilePath = _srcFile
            };

            var response = client.PutObject(objRequest);

            return(Result(response));
        }
예제 #7
0
        private void UploadToS3(string backupPath, PeriodicBackupSetup localBackupConfigs)
        {
            var awsRegion = RegionEndpoint.GetBySystemName(localBackupConfigs.AwsRegionEndpoint) ?? RegionEndpoint.USEast1;

            using (var client = new Amazon.S3.AmazonS3Client(awsAccessKey, awsSecretKey, awsRegion))
                using (var fileStream = File.OpenRead(backupPath))
                {
                    var key     = Path.GetFileName(backupPath);
                    var request = new PutObjectRequest();
                    request.WithMetaData("Description", GetArchiveDescription());
                    request.WithInputStream(fileStream);
                    request.WithBucketName(localBackupConfigs.S3BucketName);
                    request.WithKey(key);

                    using (client.PutObject(request))
                    {
                        logger.Info(string.Format("Successfully uploaded backup {0} to S3 bucket {1}, with key {2}",
                                                  Path.GetFileName(backupPath), localBackupConfigs.S3BucketName, key));
                    }
                }
        }
예제 #8
0
        private void DoUpload(string backupPath, PeriodicBackupSetup backupConfigs)
        {
            var AWSRegion = RegionEndpoint.GetBySystemName(backupConfigs.AwsRegionEndpoint) ?? RegionEndpoint.USEast1;

            var desc = string.Format("Raven.Database.Backup {0} {1}", Database.Name,
                                     DateTimeOffset.UtcNow.ToString("u"));

            if (!string.IsNullOrWhiteSpace(backupConfigs.GlacierVaultName))
            {
                var manager   = new ArchiveTransferManager(awsAccessKey, awsSecretKey, AWSRegion);
                var archiveId = manager.Upload(backupConfigs.GlacierVaultName, desc, backupPath).ArchiveId;
                logger.Info(string.Format("Successfully uploaded backup {0} to Glacier, archive ID: {1}", Path.GetFileName(backupPath),
                                          archiveId));
                return;
            }

            if (!string.IsNullOrWhiteSpace(backupConfigs.S3BucketName))
            {
                var client = new Amazon.S3.AmazonS3Client(awsAccessKey, awsSecretKey, AWSRegion);

                using (var fileStream = File.OpenRead(backupPath))
                {
                    var key     = Path.GetFileName(backupPath);
                    var request = new PutObjectRequest();
                    request.WithMetaData("Description", desc);
                    request.WithInputStream(fileStream);
                    request.WithBucketName(backupConfigs.S3BucketName);
                    request.WithKey(key);

                    using (S3Response _ = client.PutObject(request))
                    {
                        logger.Info(string.Format("Successfully uploaded backup {0} to S3 bucket {1}, with key {2}",
                                                  Path.GetFileName(backupPath), backupConfigs.S3BucketName, key));
                        return;
                    }
                }
            }
        }
예제 #9
0
        public void UploadStream(string bucketName, System.IO.Stream stream, string serverPath, int?cacheControlMaxAgeSeconds = null)
        {
            //ref: http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjSingleOpNET.html

            var region = Amazon.RegionEndpoint.GetBySystemName(this.Credential.Region);

            using (var client = new Amazon.S3.AmazonS3Client(this.Credential.AcesssKey, this.Credential.SecretKey, region))
            {
                var putRequest2 = new Amazon.S3.Model.PutObjectRequest
                {
                    BucketName  = bucketName,
                    Key         = serverPath,
                    InputStream = stream
                };

                if (cacheControlMaxAgeSeconds.HasValue)
                {
                    putRequest2.Headers.CacheControl = string.Format("max-age={0}, public", cacheControlMaxAgeSeconds);
                }

                var response2 = client.PutObject(putRequest2);
            }
        }
예제 #10
0
        /// <summary>
        /// Uploads a file to s3.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="fileBytes">The file bytes.</param>
        /// <param name="contentType">Type of the content.</param>
        public void UploadFileToS3(string key, byte[] fileBytes, string contentType, Guid fileUUID)
        {
            //http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjSingleOpNET.html
            //http://stackoverflow.com/questions/18635963/asp-net-uploading-a-file-to-amazon-s3

            var stream = new System.IO.MemoryStream(fileBytes);

            stream.Position = 0;

            var putRequest1 = new Amazon.S3.Model.PutObjectRequest
            {
                BucketName  = s3Settings.BucketName,
                Key         = key,
                InputStream = stream,
                ContentType = contentType,
                CannedACL   = new Amazon.S3.S3CannedACL(s3Settings.DefaultUploadAcl),
                ServerSideEncryptionMethod = Amazon.S3.ServerSideEncryptionMethod.None
            };

            // DEVELOPER NOTE: this this function with appfile.js file
            putRequest1.Metadata.Add("uuid", fileUUID.ToString("N"));
            Amazon.S3.Model.PutObjectResponse response1 = s3Client.PutObject(putRequest1);
        }
		private void DoUpload(string backupPath, PeriodicBackupSetup backupConfigs)
		{
			var AWSRegion = RegionEndpoint.GetBySystemName(backupConfigs.AwsRegionEndpoint) ?? RegionEndpoint.USEast1;

			var desc = string.Format("Raven.Database.Backup {0} {1}", Database.Name,
			                     DateTimeOffset.UtcNow.ToString("u"));

			if (!string.IsNullOrWhiteSpace(backupConfigs.GlacierVaultName))
			{
				var manager = new ArchiveTransferManager(awsAccessKey, awsSecretKey, AWSRegion);
				var archiveId = manager.Upload(backupConfigs.GlacierVaultName, desc, backupPath).ArchiveId;
				logger.Info(string.Format("Successfully uploaded backup {0} to Glacier, archive ID: {1}", Path.GetFileName(backupPath),
										  archiveId));
				return;
			}

			if (!string.IsNullOrWhiteSpace(backupConfigs.S3BucketName))
			{
				var client = new Amazon.S3.AmazonS3Client(awsAccessKey, awsSecretKey, AWSRegion);

				using (var fileStream = File.OpenRead(backupPath))
				{
					var key = Path.GetFileName(backupPath);
					var request = new PutObjectRequest();
					request.WithMetaData("Description", desc);
					request.WithInputStream(fileStream);
					request.WithBucketName(backupConfigs.S3BucketName);
					request.WithKey(key);

					using (S3Response _ = client.PutObject(request))
					{
						logger.Info(string.Format("Successfully uploaded backup {0} to S3 bucket {1}, with key {2}",
							Path.GetFileName(backupPath), backupConfigs.S3BucketName, key));
						return;
					}
				}
			}
		}
예제 #12
0
            public void SaveJob(string status)
            {
                string zipPath = TempFolder.FullName + "\\output.zip";
                string awsUrl  = "";

                using (FileStream zf = File.OpenWrite(zipPath))
                {
                    using (ZipOutputStream zfs = new ZipOutputStream(zf))
                    {
                        AddFiles(zfs, ZipFolder);
                        if (status == "Success")
                        {
                            if (Regex.IsMatch(Job.OutputType, "objc", RegexOptions.Compiled | RegexOptions.IgnoreCase))
                            {
                                AddResource(zfs, "NSWSDL.h", LibResources.NSWSDL_H);
                                AddResource(zfs, "NSWSDL.M", LibResources.NSWSDL_M);
                                AddResource(zfs, "help.html", LibResources.objc_help);
                            }
                            else
                            {
                                if (Regex.IsMatch(Job.OutputTarget, "android", RegexOptions.Compiled | RegexOptions.IgnoreCase))
                                {
                                    AddResource(zfs, "wsclient.android.jar", LibResources.wsclient_android);
                                }
                                else if (Regex.IsMatch(Job.OutputTarget, "blackberry", RegexOptions.Compiled | RegexOptions.IgnoreCase))
                                {
                                    AddResource(zfs, "wsclient.blackberry.jar", LibResources.wsclient_blackberry);
                                }
                                else
                                {
                                    AddResource(zfs, "wsclient.jar", LibResources.wsclient);
                                }
                                AddResource(zfs, "help.html", LibResources.java_help);
                            }
                        }
                    }
                }

                using (Amazon.S3.AmazonS3Client client = CreateS3Client())
                {
                    PutObjectRequest obj = new PutObjectRequest();
                    obj.BucketName = "wsclient";

                    string key = GetNewKey() + ".zip";

                    obj.Key         = "jobs/" + Job.JobID + "/" + key;
                    awsUrl          = obj.Key;
                    obj.FilePath    = zipPath;
                    obj.ContentType = "application/octat-stream";
                    obj.CannedACL   = Amazon.S3.S3CannedACL.PublicRead;
                    client.PutObject(obj);
                }

                using (WebClient client = new WebClient())
                {
                    client.Headers[HttpRequestHeader.ContentType] = "application/json";
                    SetupAuth(client.Headers);
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string data             = js.Serialize(new
                    {
                        JobStatus = status,
                        ResultUrl = "https://s3.amazonaws.com/wsclient/" + awsUrl
                    });
                    string result = client.UploadString(Host + "/api/jobs/update/" + Job.JobID + "?_=" + DateTime.UtcNow.Ticks, "POST", data);
                }
            }
예제 #13
0
        public void Execute(JobExecutionContext context)
        {
            //Get Current Batch
            //Close Current Batch
            //And Open New One
            //Create a new BatchFile Record
            logger.Log(LogLevel.Info, String.Format("Creating Nacha ACH File at {0}", System.DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")));

            logger.Log(LogLevel.Info, String.Format("Batching Transactions"));
            var transactions = transactionBatchService.BatchTransactions();

            FileGenerator fileGeneratorService = new FileGenerator();
            fileGeneratorService.CompanyIdentificationNumber = ConfigurationManager.AppSettings["CompanyIdentificationNumber"];
            fileGeneratorService.CompanyName = ConfigurationManager.AppSettings["CompanyName"];
            fileGeneratorService.ImmediateDestinationId = ConfigurationManager.AppSettings["ImmediateDestinationId"];
            fileGeneratorService.ImmediateDestinationName = ConfigurationManager.AppSettings["ImmediateDestinationName"];
            fileGeneratorService.ImmediateOriginId = ConfigurationManager.AppSettings["ImmediateOriginId"];
            fileGeneratorService.ImmediateOriginName = ConfigurationManager.AppSettings["ImmediateOriginName"];
            fileGeneratorService.OriginatingTransitRoutingNumber = ConfigurationManager.AppSettings["OriginatingTransitRoutingNumber"];
            fileGeneratorService.CompanyDiscretionaryData = ConfigurationManager.AppSettings["CompanyDiscretionaryData"];

            logger.Log(LogLevel.Info, String.Format("Processing Transactions"));

            var results = fileGeneratorService.ProcessFile(transactions);

            logger.Log(LogLevel.Info, String.Format("Creating Batch File"));

            StringBuilder sb = new StringBuilder();
            results.ForEach(s => sb.AppendLine(s));
            string fileContext = sb.ToString();

            logger.Log(LogLevel.Info, String.Format("Uploading Batch File to S3 Server"));

            string bucketName = ConfigurationManager.AppSettings["NachaFileBucketName"];
            if (String.IsNullOrEmpty(bucketName))
                throw new Exception("S3 bucket name for NachaFileBucketName not configured");

            Amazon.S3.AmazonS3Client s3Client = new Amazon.S3.AmazonS3Client();
            PutObjectRequest putRequest = new PutObjectRequest()
            {
                ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256,
                BucketName = bucketName,
                ContentBody = fileContext,
                Key = "NACHA_FILE_" + System.DateTime.Now.ToString("MMddyy_Hmmss")
            };
            s3Client.PutObject(putRequest);

            //Move all payments to paid
            //Update Batch File
            //Start BatchFile Workflow
        }
예제 #14
0
        public ActionResult Edit(TimelineEvent timelineEvent)
        {
            try
            {
                var file = Request.Files["file"];

                if (file != null && file.FileName.EndsWith(".png") || file.FileName.EndsWith(".jpg"))
                {
                    var fullPath = Server.MapPath("/" + file.FileName);
                    file.SaveAs(fullPath);

                    var config = new Amazon.S3.AmazonS3Config {
                        MaxErrorRetry = 0
                    };
                    var client = new Amazon.S3.AmazonS3Client("AKIAJTSDXO36LAHQEOJA", "+HW/vJzJ+XApMYhBzVtAYElxiEZIVw24NXTYBtiG", config);

                    var req = new Amazon.S3.Model.PutObjectRequest {
                        BucketName = "10years-dawitisaak",
                        FilePath = fullPath
                    };
                    var res = client.PutObject(req);

                    timelineEvent.Image = res.AmazonId2;
                }

                // TODO: Add update logic here
                timelineEvent = timelineService.Save(timelineEvent);

                return RedirectToAction("Details", new { id = timelineEvent.Id });
            }
            catch(Exception ex)
            {
                throw ex;
                ModelState.AddModelError("Could not Edit", ex);
                return View(timelineEvent);
            }
        }
        /// <summary>
        /// Uploads the drawing to Amazon S3
        /// </summary>
        /// <param name="dwgFilePath"></param>
        /// <returns>Presigned Url of the uploaded drawing file in Amazon S3</returns>
        public static String UploadDrawingToS3(String dwgFilePath)
        {
            String s3URL = String.Empty;

            try
            {
                if (!System.IO.File.Exists(dwgFilePath))
                {
                    return(s3URL);
                }

                String keyName = System.IO.Path.GetFileName(dwgFilePath);

                //be sure to connect to the endpoint which is the same region of your bucket!
                using (Amazon.S3.IAmazonS3 client = new Amazon.S3.AmazonS3Client(Amazon.RegionEndpoint.USWest2))
                {
                    Amazon.S3.Model.PutObjectRequest putRequest1 = new Amazon.S3.Model.PutObjectRequest
                    {
                        BucketName  = S3BucketName,
                        Key         = keyName,
                        ContentBody = "sample text"
                    };

                    Amazon.S3.Model.PutObjectResponse response1 = client.PutObject(putRequest1);

                    Amazon.S3.Model.PutObjectRequest putRequest2 = new Amazon.S3.Model.PutObjectRequest
                    {
                        BucketName  = S3BucketName,
                        Key         = keyName,
                        FilePath    = dwgFilePath,
                        ContentType = "application/acad"
                    };
                    putRequest2.Metadata.Add("x-amz-meta-title", keyName);

                    Amazon.S3.Model.PutObjectResponse response2 = client.PutObject(putRequest2);

                    Amazon.S3.Model.GetPreSignedUrlRequest request1 = new Amazon.S3.Model.GetPreSignedUrlRequest
                    {
                        BucketName = S3BucketName,
                        Key        = keyName,
                        Expires    = DateTime.Now.AddMinutes(5)
                    };

                    s3URL = client.GetPreSignedURL(request1);

                    Console.WriteLine(s3URL);
                }
            }
            catch (Amazon.S3.AmazonS3Exception amazonS3Exception)
            {
                if (amazonS3Exception.ErrorCode != null &&
                    (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") ||
                     amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    Console.WriteLine("Check the provided AWS Credentials.");
                    Console.WriteLine("For service sign up go to http://aws.amazon.com/s3");
                }
                else
                {
                    Console.WriteLine("Error occurred. Message:'{0}' when writing an object", amazonS3Exception.Message);
                }
            }
            return(s3URL);
        }
예제 #16
0
		private void UploadToS3(string backupPath, PeriodicBackupSetup localBackupConfigs)
		{
			var awsRegion = RegionEndpoint.GetBySystemName(localBackupConfigs.AwsRegionEndpoint) ?? RegionEndpoint.USEast1;

			using (var client = new Amazon.S3.AmazonS3Client(awsAccessKey, awsSecretKey, awsRegion))
			using (var fileStream = File.OpenRead(backupPath))
			{
				var key = Path.GetFileName(backupPath);
				var request = new PutObjectRequest();
				request.WithMetaData("Description", GetArchiveDescription());
				request.WithInputStream(fileStream);
				request.WithBucketName(localBackupConfigs.S3BucketName);
				request.WithKey(key);

				using (client.PutObject(request))
				{
					logger.Info(string.Format("Successfully uploaded backup {0} to S3 bucket {1}, with key {2}",
											  Path.GetFileName(backupPath), localBackupConfigs.S3BucketName, key));
				}
			}
		}
        /// <summary>
        /// Uploads the drawing to Amazon S3
        /// </summary>
        /// <param name="dwgFilePath"></param>
        /// <returns>Presigned Url of the uploaded drawing file in Amazon S3</returns>
        public static String UploadDrawingToS3(String dwgFilePath)
        {
            String s3URL = String.Empty;

            try
            {
                if (!System.IO.File.Exists(dwgFilePath))
                    return s3URL;

                String keyName = System.IO.Path.GetFileName(dwgFilePath);

                using (Amazon.S3.IAmazonS3 client = new Amazon.S3.AmazonS3Client(Amazon.RegionEndpoint.APSoutheast1))
                {
                    Amazon.S3.Model.PutObjectRequest putRequest1 = new Amazon.S3.Model.PutObjectRequest
                    {
                        BucketName = S3BucketName,
                        Key = keyName,
                        ContentBody = "sample text"
                    };

                    Amazon.S3.Model.PutObjectResponse response1 = client.PutObject(putRequest1);

                    Amazon.S3.Model.PutObjectRequest putRequest2 = new Amazon.S3.Model.PutObjectRequest
                    {
                        BucketName = S3BucketName,
                        Key = keyName,
                        FilePath = dwgFilePath,
                        ContentType = "application/acad"
                    };
                    putRequest2.Metadata.Add("x-amz-meta-title", keyName);

                    Amazon.S3.Model.PutObjectResponse response2 = client.PutObject(putRequest2);

                    Amazon.S3.Model.GetPreSignedUrlRequest request1 = new Amazon.S3.Model.GetPreSignedUrlRequest
                    {
                        BucketName = S3BucketName,
                        Key = keyName,
                        Expires = DateTime.Now.AddMinutes(5)
                    };

                    s3URL = client.GetPreSignedURL(request1);

                    Console.WriteLine(s3URL);
                }
            }
            catch (Amazon.S3.AmazonS3Exception amazonS3Exception)
            {
                if (amazonS3Exception.ErrorCode != null &&
                    (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") ||
                    amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    Console.WriteLine("Check the provided AWS Credentials.");
                    Console.WriteLine("For service sign up go to http://aws.amazon.com/s3");
                }
                else
                {
                    Console.WriteLine("Error occurred. Message:'{0}' when writing an object", amazonS3Exception.Message);
                }
            }
            return s3URL;
        }