Пример #1
0
        public override async Task SaveAsync(BlobProviderSaveArgs args)
        {
            var blobName      = AwsBlobNameCalculator.Calculate(args);
            var configuration = args.Configuration.GetAwsConfiguration();
            var containerName = GetContainerName(args);

            using (var amazonS3Client = await GetAmazonS3Client(args))
            {
                if (!args.OverrideExisting && await BlobExistsAsync(amazonS3Client, containerName, blobName))
                {
                    throw new BlobAlreadyExistsException(
                              $"Saving BLOB '{args.BlobName}' does already exists in the container '{containerName}'! Set {nameof(args.OverrideExisting)} if it should be overwritten.");
                }

                if (configuration.CreateContainerIfNotExists)
                {
                    await CreateContainerIfNotExists(amazonS3Client, containerName);
                }

                await amazonS3Client.PutObjectAsync(new PutObjectRequest
                {
                    BucketName  = containerName,
                    Key         = blobName,
                    InputStream = args.BlobStream
                });
            }
        }
Пример #2
0
        public override async Task <bool> ExistsAsync(BlobProviderExistsArgs args)
        {
            var blobName      = AwsBlobNameCalculator.Calculate(args);
            var containerName = GetContainerName(args);

            using (var amazonS3Client = await GetAmazonS3Client(args))
            {
                return(await BlobExistsAsync(amazonS3Client, containerName, blobName));
            }
        }
Пример #3
0
        public override async Task <bool> DeleteAsync(BlobProviderDeleteArgs args)
        {
            var blobName      = AwsBlobNameCalculator.Calculate(args);
            var containerName = GetContainerName(args);

            using (var amazonS3Client = await GetAmazonS3Client(args))
            {
                if (!await BlobExistsAsync(amazonS3Client, containerName, blobName))
                {
                    return(false);
                }

                await amazonS3Client.DeleteObjectAsync(new DeleteObjectRequest
                {
                    BucketName = containerName,
                    Key        = blobName
                });

                return(true);
            }
        }
Пример #4
0
    public override async Task <Stream> GetOrNullAsync(BlobProviderGetArgs args)
    {
        var blobName      = AwsBlobNameCalculator.Calculate(args);
        var containerName = GetContainerName(args);

        using (var amazonS3Client = await GetAmazonS3Client(args))
        {
            if (!await BlobExistsAsync(amazonS3Client, containerName, blobName))
            {
                return(null);
            }

            var response = await amazonS3Client.GetObjectAsync(new GetObjectRequest
            {
                BucketName = containerName,
                Key        = blobName
            });

            return(await TryCopyToMemoryStreamAsync(response.ResponseStream, args.CancellationToken));
        }
    }
Пример #5
0
        public async override Task <Stream> GetOrNullAsync(BlobProviderGetArgs args)
        {
            var blobName      = AwsBlobNameCalculator.Calculate(args);
            var containerName = GetContainerName(args);

            using (var amazonS3Client = await GetAmazonS3Client(args))
            {
                if (!await BlobExistsAsync(amazonS3Client, containerName, blobName))
                {
                    return(null);
                }

                var response = await amazonS3Client.GetObjectAsync(new GetObjectRequest
                {
                    BucketName = containerName,
                    Key        = blobName
                });

                var memoryStream = new MemoryStream();
                await response.ResponseStream.CopyToAsync(memoryStream);

                return(memoryStream);
            }
        }