Provides configuration options for how TransferUtility processes requests.

The best configuration settings depend on network configuration, latency and bandwidth. The default configuration settings are suitable for most applications, but this class enables developers to experiment with different configurations and tune transfer manager performance.

 public async Task UploadFile(string name,IStorageFile storageFile)
 {            
     var s3Client = new AmazonS3Client(credentials, RegionEndpoint.USEast1);
     var transferUtilityConfig = new TransferUtilityConfig
     {                
         ConcurrentServiceRequests = 5,                
         MinSizeBeforePartUpload = 20 * MB_SIZE,
     };
     try
     {
         using (var transferUtility = new TransferUtility(s3Client, transferUtilityConfig))
         {
             var uploadRequest = new TransferUtilityUploadRequest
             {
                 BucketName = ExistingBucketName,
                 Key = name,
                 StorageFile = storageFile,
                 // Set size of each part for multipart upload to 10 MB
                 PartSize = 10 * MB_SIZE
             };
             uploadRequest.UploadProgressEvent += OnUploadProgressEvent;
             await transferUtility.UploadAsync(uploadRequest);
         }
     }
     catch (AmazonServiceException ex)
     {
       //  oResponse.OK = false;
      //   oResponse.Message = "Network Error when connecting to AWS: " + ex.Message;
     }
 }
Ejemplo n.º 2
0
        public AwsFileUpload(String name, String sourceFilePath, Stream stream, String bucketName, String accessKey, String secretKey, string originalFileName, string note, DateTime originalFileDate, bool isDownload, string md5, Int32 duration = 0, string resolution = "")
            : base(name, sourceFilePath, stream, originalFileName, note, originalFileDate, isDownload, duration, resolution)
        {
            this._bucketName = bucketName;

            if (!string.IsNullOrEmpty(md5))
                base._md5 = md5;


            var fileTransferUtilityConfig = new TransferUtilityConfig { ConcurrentServiceRequests = 10 };
            AWSConfigs.S3Config.UseSignatureVersion4 = true;
            string regionFromConfig = System.Configuration.ConfigurationSettings.AppSettings.Get("EndpointRegion");


            RegionEndpoint regionEndpoint = RegionEndpoint.APNortheast1;

            switch (regionFromConfig.ToLower())
            {
                case "apsoutheast1":
                    regionEndpoint = RegionEndpoint.APSoutheast1;
                    break;
                case "apsoutheast2":
                    regionEndpoint = RegionEndpoint.APSoutheast2;
                    break;
                case "cnnorth1":
                    regionEndpoint = RegionEndpoint.CNNorth1;
                    break;
                case "eucentral1":
                    regionEndpoint = RegionEndpoint.EUCentral1;
                    break;
                case "euwest1":
                    regionEndpoint = RegionEndpoint.EUWest1;
                    break;
                case "saeast1":
                    regionEndpoint = RegionEndpoint.SAEast1;
                    break;
                case "useast1":
                    regionEndpoint = RegionEndpoint.USEast1;
                    break;
                case "usgovcloudwest1":
                    regionEndpoint = RegionEndpoint.USGovCloudWest1;
                    break;
                case "uswest1":
                    regionEndpoint = RegionEndpoint.USWest1;
                    break;
                case "uswest2":
                    regionEndpoint = RegionEndpoint.USWest2;
                    break;
                default: break; //APNortheast1
            }


            _amazonS3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey), regionEndpoint);
            _amazonS3Client.ExceptionEvent += amazonS3Client_ExceptionEvent;

            _fileTransferUtility = new TransferUtility(_amazonS3Client, fileTransferUtilityConfig);
        }
 public AmazonS3StorageProvider(IAmazonS3StorageConfiguration amazonS3StorageConfiguration)
 {
     _amazonS3StorageConfiguration = amazonS3StorageConfiguration;
     var cred = new BasicAWSCredentials(_amazonS3StorageConfiguration.AWSAccessKey, _amazonS3StorageConfiguration.AWSSecretKey);
     //TODO: aws region to config
     _client = new AmazonS3Client(cred, RegionEndpoint.USEast1);
     var config = new TransferUtilityConfig();
     _transferUtility = new TransferUtility(_client, config);
 }
 /// <summary>
 ///     Constructs a new <see cref="TransferUtility"/> class.
 /// </summary>
 /// <param name="config">
 ///     Specifies advanced configuration settings for <see cref="TransferUtility"/>.
 /// </param>
 /// <remarks>
 /// </remarks>
 public TransferUtility(TransferUtilityConfig config)
     : this(new AmazonS3Client(), config)
 {
     this._config = config;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 	Initializes a new instance of the <see cref="TransferUtility"/> class.
 /// </summary>
 /// <param name="s3Client">
 /// 	The Amazon S3 client.
 /// </param>
 /// <param name="config">
 /// 	The advanced configuration settings for <see cref="TransferUtility"/>.
 /// </param>
 public TransferUtility(AmazonS3 s3Client, TransferUtilityConfig config)
 {
     this._s3Client = s3Client;
     this._config = config;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 	Constructs a new instance of the <see cref="TransferUtility"/> class.
 /// </summary>
 /// <param name="awsAccessKeyId">
 /// 	The AWS Access Key ID.
 /// </param>
 /// <param name="awsSecretAccessKey">
 /// 	The AWS Secret Access Key.
 /// </param>
 /// <param name="config">
 /// 	The config for setting advances settings.
 /// </param>
 public TransferUtility(string awsAccessKeyId, string awsSecretAccessKey, TransferUtilityConfig config)
     : this(new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey), config)
 {
     this._shouldDispose = true;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 	Constructs a new instance of the <see cref="TransferUtility"/> class.
 /// </summary>
 /// <param name="awsAccessKeyId">
 /// 	The AWS Access Key ID.
 /// </param>
 /// <param name="awsSecretAccessKey">
 /// 	The AWS Secret Access Key.
 /// </param>
 /// <param name="config">
 /// 	Specifies advanced settings.
 /// </param>
 public TransferUtility(string awsAccessKeyId, string awsSecretAccessKey, TransferUtilityConfig config)
     : this(awsAccessKeyId, awsSecretAccessKey, RegionEndpoint.USEast1, config)
 {
     this._shouldDispose = true;
 }
Ejemplo n.º 8
0
 /// <summary>
 ///     Constructs a new <see cref="TransferUtility"/> class.
 /// </summary>
 /// <param name="config">
 ///     Specifies advanced configuration settings for <see cref="TransferUtility"/>.
 /// </param>
 /// <remarks>
 /// </remarks>
 public TransferUtility(TransferUtilityConfig config)
     : this(new AmazonS3Client(), config)
 {
     this._shouldDispose = true;
     this._config        = config;
 }
Ejemplo n.º 9
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="TransferUtility"/> class.
 /// </summary>
 /// <param name="s3Client">
 ///     The Amazon S3 client.
 /// </param>
 /// <param name="config">
 ///     Specifies advanced configuration settings for <see cref="TransferUtility"/>.
 /// </param>
 public TransferUtility(AmazonS3 s3Client, TransferUtilityConfig config)
 {
     this._s3Client = s3Client;
     this._config   = config;
 }
Ejemplo n.º 10
0
 /// <summary>
 ///     Constructs a new instance of the <see cref="TransferUtility"/> class.
 /// </summary>
 /// <param name="awsAccessKeyId">
 ///     The AWS Access Key ID.
 /// </param>
 /// <param name="awsSecretAccessKey">
 ///     The AWS Secret Access Key.
 /// </param>
 /// <param name="region">
 ///     The region to configure the transfer utility for.
 /// </param>
 /// <param name="config">
 ///     Specifies advanced settings.
 /// </param>
 public TransferUtility(string awsAccessKeyId, string awsSecretAccessKey, RegionEndpoint region, TransferUtilityConfig config)
     : this(new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey, region), config)
 {
     this._shouldDispose = true;
 }
Ejemplo n.º 11
0
 /// <summary>
 ///     Constructs a new instance of the <see cref="TransferUtility"/> class.
 /// </summary>
 /// <param name="awsAccessKeyId">
 ///     The AWS Access Key ID.
 /// </param>
 /// <param name="awsSecretAccessKey">
 ///     The AWS Secret Access Key.
 /// </param>
 /// <param name="config">
 ///     Specifies advanced settings.
 /// </param>
 public TransferUtility(string awsAccessKeyId, string awsSecretAccessKey, TransferUtilityConfig config)
     : this(awsAccessKeyId, awsSecretAccessKey, RegionEndpoint.USEast1, config)
 {
     this._shouldDispose = true;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 	Constructs a new <see cref="TransferUtility"/> class.
 /// </summary>
 /// <param name="config">
 /// 	Specifies advanced configuration settings for <see cref="TransferUtility"/>.
 /// </param>
 /// <remarks>
 /// </remarks>
 public TransferUtility(TransferUtilityConfig config)
     : this(new AmazonS3Client(), config)
 {
     this._config = config;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 	Constructs a new <see cref="TransferUtility"/> class.
 /// </summary>
 /// <param name="config">
 /// 	Specifies advanced configuration settings for <see cref="TransferUtility"/>.
 /// </param>
 /// <remarks>
 /// </remarks>
 public TransferUtility(TransferUtilityConfig config)
     : this(new AmazonS3Client(), config)
 {
     this._shouldDispose = true;
     this._config = config;
 }
Ejemplo n.º 14
0
        //public async Task  UploadFileAsync(string name, IStorageFile storageFile, FileUploadCompleted fileinfo)
        //{
        //   await  Task.Factory.StartNew(() => UploadFile( name,  storageFile,  fileinfo));

        //}

        public async void UploadFile(string name, IStorageFile storageFile, FileUploadCompleted fileinfo)
        {
            fileinfo.UploadStartTime = DateTime.Now;
            BasicAWSCredentials credentials = new BasicAWSCredentials("AKIAJTADDHY7T7GZXX5Q", "n4xV5B25mt7e6br84H2G9SXBx8eDYTQJgCxoaF49");
            var s3Client = new AmazonS3Client(credentials, RegionEndpoint.USEast1);
            var transferUtilityConfig = new TransferUtilityConfig
            {
                ConcurrentServiceRequests = 5,
                MinSizeBeforePartUpload = 20 * MB_SIZE,
            };
            try
            {
                using (var transferUtility = new TransferUtility(s3Client, transferUtilityConfig))
                {
                    var uploadRequest = new TransferUtilityUploadRequest
                    {
                        BucketName = ExistingBucketName,
                        Key = name,
                        StorageFile = storageFile,
                        // Set size of each part for multipart upload to 10 MB
                        PartSize = 10 * MB_SIZE,
                        CannedACL = S3CannedACL.PublicRead                       
                    };
                   
                    uploadRequest.UploadProgressEvent += OnUploadProgressEvent;
                   // fileinfo.Status = currentStatus.ToString();
                    try
                    {
                        await transferUtility.UploadAsync(uploadRequest);
                    }
                    catch
                    {

                    }
                   // fileinfo.UploadEndtime = DateTime.Now;
                }
            }
            catch (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);
                }
            }
        }