Beispiel #1
0
        public void Open(string accessKey, string secretAccessKey, string path)
        {
            string bucketName, keyName;

            if (!S3Path.TryParse(path, out bucketName, out keyName))
            {
                throw new ArgumentException("path");
            }
            if (string.IsNullOrEmpty(bucketName))
            {
                throw new ArgumentException("bucketName");
            }
            if (string.IsNullOrEmpty(keyName))
            {
                throw new ArgumentException("keyName");
            }

            this.BucketName = bucketName;
            this.KeyName    = keyName;

            if (string.IsNullOrEmpty(accessKey) || string.IsNullOrEmpty(secretAccessKey))
            {
                _s3Client = S3Client.GetInstance(bucketName);
            }
            else
            {
                _s3Client = S3Client.GetInstance(accessKey, secretAccessKey, bucketName);
            }

            GetObjectMetadataResponse getObjectMetadataResponse = getObjectMetadata(_s3Client, bucketName, keyName);

            this.Length = getObjectMetadataResponse.ContentLength;

            _objectRequests.Clear();
            _objectRequestToDownload.Clear();
            _objectPartsCache.Clear();

            S3ObjectRequest[] objectRequests = getObjectRequests(bucketName, keyName, this.Length, this.Capacity);
            foreach (S3ObjectRequest objectRequest in objectRequests)
            {
                _objectRequests.Enqueue(objectRequest);
            }

            _isOpen    = true;
            _readBytes = 0;

            startThread();

            _timer = new Timer(timerCallBack, null, Timeout.Infinite, Timeout.Infinite);
            startTimer();
        }
Beispiel #2
0
        public static AmazonS3Client GetInstance(string bucketName)
        {
            // Bucket Location
            RegionEndpoint regionEndPoint;

            using (IAmazonS3 s3Client = S3Client.GetInstance())
            {
                regionEndPoint = S3Client.GetBucketLocation(s3Client, bucketName);
            }

            // Transfer Acceleration
            using (IAmazonS3 s3Client = S3Client.GetInstance(regionEndPoint))
            {
                BucketAccelerateStatus accelerateStatus = s3Client.GetBucketAccelerateConfiguration(bucketName).Status;
                AmazonS3Config         amazonS3Config   = new AmazonS3Config()
                {
                    RegionEndpoint        = regionEndPoint,
                    UseAccelerateEndpoint = accelerateStatus == BucketAccelerateStatus.Enabled ? true : false,
                    ReadWriteTimeout      = Timeout
                };

                return(GetInstance(amazonS3Config));
            }
        }