Example #1
0
 public S3FileStorageService(IAmazonS3 s3Client,
                             IOptions <S3Options> settings,
                             ITransferUtility transferUtility)
 {
     _transferUtility = transferUtility;
     _settings        = settings.Value;
     _s3Client        = s3Client;
 }
Example #2
0
    public void SetUp()
    {
        var credentialsOptions  = new CredentialsOptions();
        var credentialsProvider = new CredentialsProvider(credentialsOptions);
        var options             = new S3Options <S3ContextTests>();

        _context = new S3Context <S3ContextTests>(credentialsProvider, options);
    }
Example #3
0
        public static IServiceCollection AddS3 <T>(
            this IServiceCollection services,
            S3Options <T> configuration
            )
        {
            services.TryAddSingleton(configuration);
            services.TryAddSingleton <S3Context <T> >();

            return(services);
        }
        public IAmazonS3 Create(S3Options settings)
        {
            AWSCredentials credentials = new BasicAWSCredentials(settings.AccessKey, settings.SecretKey);
            AmazonS3Config config      = new AmazonS3Config
            {
                ServiceURL     = settings.Api,
                ForcePathStyle = true
            };

            return(new AmazonS3Client(credentials, config));
        }
Example #5
0
 public S3FileStorage(IS3BucketClientFactory bucketClientFactory, S3Options options)
 {
     this.bucketClientFactory = bucketClientFactory;
     this.options             = options;
 }
Example #6
0
 public S3Facade(IOptions <S3Options> s3Options)
 {
     _s3Options = s3Options.Value;
 }
Example #7
0
 public S3StorageClient(S3Options s3Options)
 {
     _s3Options = s3Options;
 }
Example #8
0
        private static void UploadFileToS3Storage(string fileContent, string fileName, S3Options s3Options)
        {
            var config = new AmazonS3Config()
            {
                ServiceURL     = s3Options.ServiceURL,
                ForcePathStyle = s3Options.ForcePathStyle
            };

            using var client     = new AmazonS3Client(s3Options.AccessKeyID, s3Options.Key, config);
            using var fileStream = new MemoryStream(Encoding.UTF8.GetBytes(fileContent));

            var folder = string.IsNullOrEmpty(s3Options.DestinationFolder) ? string.Empty : $"{s3Options.DestinationFolder}/";

            client.PutObjectAsync(new PutObjectRequest
            {
                BucketName  = s3Options.BucketName,
                Key         = $"{folder}{fileName}",
                InputStream = fileStream
            }).Wait();
        }