예제 #1
0
        public async Task UploadFileToS3Async(S3Credentials sc, IFormFile f)
        {
            RegionEndpoint bucketRegion = RegionEndpoint.USEast1;

            var sessionCredentials =
                new SessionAWSCredentials(sc.AccessKeyId,
                                          sc.SecretAccessKey,
                                          sc.SessionToken);

            IAmazonS3 s3Client = new AmazonS3Client(sessionCredentials, bucketRegion);

            try
            {
                var fileTransferUtility =
                    new TransferUtility(s3Client);

                await fileTransferUtility.UploadAsync(f.OpenReadStream(),
                                                      sc.Bucket, sc.Key);

                Console.WriteLine("Upload 3 completed");
            }
            catch (AmazonS3Exception e)
            {
                Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
            }
        }
예제 #2
0
        public async Task OnPostAsync(IFormFile formFile)
        {
            Data = await _mapService.GetS3Credentials();

            await _mapService.UploadFileToS3Async(Data, formFile);

            MapBoxResponse = await _mapService.UploadToMapBox(Data, $"{TileName}{DateTime.Now.Ticks}");
        }
예제 #3
0
        /// <param name="bucketName">S3 bucket name</param>
        /// <param name="keyFile">Api key for S3</param>
        /// <param name="crypto_key">3-DES key</param>
        /// <param name="crypto_iv">3-DES vector</param>
        public S3ObjectRestore(string bucketName, string keyFile, byte[] crypto_key, byte[] crypto_iv, ILogging logger)
        {
            _bucketName = bucketName ?? throw new ArgumentNullException("bucketName");
            _keyFile    = keyFile ?? throw new ArgumentNullException("keyFile");
            _crypto_key = crypto_key ?? throw new ArgumentNullException("key");
            _crypto_iv  = crypto_iv ?? throw new ArgumentNullException("iv");
            _logger     = logger ?? throw new ArgumentNullException("logger");

            S3Credentials credentials = S3Credentials.LoadKey(keyFile);

            _client = new AmazonS3Client(credentials.AccessKeyId, credentials.SecretAccessKey, credentials.AwsRegion);
        }
예제 #4
0
        public override void Configure(IConfigSectionNode node)
        {
            base.Configure(node);
            var accessKey = node.AttrByName(CONFIG_ACCESSKEY_ATTR).Value;
            var secretKey = node.AttrByName(CONFIG_SECRETKEY_ATTR).Value;

            if (accessKey.IsNotNullOrWhiteSpace())
            {
                var cred = new S3Credentials(accessKey, secretKey);
                var at   = new AuthenticationToken(Bucket, accessKey);
                User = new User(cred, at, UserStatus.User, accessKey, accessKey, Rights.None);
            }
        }
예제 #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        public S3BucketDestination(string bucketName, string keyFile)
        {
            if (string.IsNullOrWhiteSpace(bucketName))
            {
                throw new ArgumentNullException("bucketName");
            }

            if (string.IsNullOrWhiteSpace(keyFile))
            {
                throw new ArgumentNullException("keyFile");
            }

            _bucketName = bucketName;

            S3Credentials credentials = S3Credentials.LoadKey(keyFile);

            _client = new AmazonS3Client(credentials.AccessKeyId, credentials.SecretAccessKey, credentials.AwsRegion);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public S3BucketSource(string bucketName, string keyFile, IProgressing progress, bool wideDisplay)
        {
            if (string.IsNullOrWhiteSpace(bucketName))
            {
                throw new ArgumentNullException("bucketName");
            }

            if (string.IsNullOrWhiteSpace(keyFile))
            {
                throw new ArgumentNullException("keyFile");
            }

            _progress = progress ?? throw new ArgumentNullException("progress");

            _bucketName  = bucketName;
            _wideDisplay = wideDisplay;

            S3Credentials credentials = S3Credentials.LoadKey(keyFile);

            _client = new AmazonS3Client(credentials.AccessKeyId, credentials.SecretAccessKey, credentials.AwsRegion);
        }
예제 #7
0
        public async Task <MapBoxResponse> UploadToMapBox(S3Credentials sc, string tile_set_name)
        {
            var client = _clientFactory.CreateClient();

            var dt = new SendData {
                url = $"{sc.Url}", tileset = $"{MAPBOXUSERNAME}.{tile_set_name}"
            };

            var resposne = await client.PostAsync($"https://api.mapbox.com/uploads/v1/geosmart?access_token=sk.eyJ1IjoiZ2Vvc21hcnQiLCJhIjoiY2tleHlydWtyMDV1bjJ6cGh0OHR5MWJvZiJ9.6CsLA0F0xiSTNygsPYKcOA", new StringContent(JsonSerializer.Serialize(dt), Encoding.UTF8, "application/json"));

            if (resposne.IsSuccessStatusCode)
            {
                using var stream = await resposne.Content.ReadAsStreamAsync();

                var data = await JsonSerializer.DeserializeAsync <MapBoxResponse>(stream);

                return(data);
            }
            else
            {
                return(null);
            }
        }
예제 #8
0
        public override void Configure(IConfigSectionNode node)
        {
            base.Configure(node);
              var accessKey = node.AttrByName(CONFIG_ACCESSKEY_ATTR).Value;
              var secretKey = node.AttrByName(CONFIG_SECRETKEY_ATTR).Value;

              if (accessKey.IsNotNullOrWhiteSpace())
            {
            var cred = new S3Credentials(accessKey, secretKey);
            var at = new AuthenticationToken(Bucket, accessKey);
            User = new User(cred, at, UserStatus.User, accessKey, accessKey, Rights.None);
            }
        }