SalesForceBackup/S3Uploader.cs
/// <summary>
/// Uploads a file to S3.
/// </summary>
/// <param name="file">The full filename and path of the file to upload.</param>
Uploads a file to S3.
Uploads a file to S3 .
public void Upload(string file)
        {
            var filename = Path.GetFileName(file);
            try
            {
                var credentials = new BasicAWSCredentials(_appSettings.Get(AppSettingKeys.AwsAccessKey), _appSettings.Get(AppSettingKeys.AwsSecretKey));
                var region = RegionEndpoint.GetBySystemName(_appSettings.Get(AppSettingKeys.AwsRegion));
                using (var client = new AmazonS3Client(credentials, region))
                {
                    var request = new PutObjectRequest
                    {
                        BucketName = _appSettings.Get(AppSettingKeys.S3Bucket),
                        Key = String.Join("/", new[] { _appSettings.Get(AppSettingKeys.S3Folder), filename }),
                        FilePath = file
                    };
                    Console.WriteLine("Uploading {0} to AWS S3...", filename);
                    client.PutObject(request);
                }
            }
            catch (AmazonS3Exception e)
            {
                if (e.ErrorCode != null && (e.ErrorCode.Equals("InvalidAccessKeyId") || e.ErrorCode.Equals("InvalidSecurity")))
                {
                    _errorHandler.HandleError(e, (int)Enums.ExitCode.AwsCredentials, "Check the provided AWS Credentials");
                }
                else
                {
                    _errorHandler.HandleError(e, (int)Enums.ExitCode.AwsS3Error, String.Format("Error occurred. Message:'{0}' when writing an object", e.Message));
                }
            }
        }
public void Upload ( string file ) { var filename = Path . GetFileName ( file ) ; try { var credentials = new BasicAWSCredentials ( _appSettings . Get ( AppSettingKeys . AwsAccessKey ) , _appSettings . Get ( AppSettingKeys . AwsSecretKey ) ) ; var region = RegionEndpoint . GetBySystemName ( _appSettings . Get ( AppSettingKeys . AwsRegion ) ) ; using ( var client = new AmazonS3Client ( credentials , region ) ) { var request = new PutObjectRequest { BucketName = _appSettings . Get ( AppSettingKeys . S3Bucket ) , Key = String . Join ( " " , new [ ] { _appSettings . Get ( AppSettingKeys . S3Folder ) , filename } ) , FilePath = file } ; Console . WriteLine ( " " , filename ) ; client . PutObject ( request ) ; } } catch ( AmazonS3Exception e ) { if ( e . ErrorCode != null && ( e . ErrorCode . Equals ( " " ) || e . ErrorCode . Equals ( " " ) ) ) { _errorHandler . HandleError ( e , ( int ) Enums . ExitCode . AwsCredentials , " " ) ; } else { _errorHandler . HandleError ( e , ( int ) Enums . ExitCode . AwsS3Error , String . Format ( " " , e . Message ) ) ; } } }
Uploads a file to S3.
Uploads a file to S3 .
file
string
The full filename and path of the file to upload.
The full filename and path of the file to upload .