Open Closed

Use another server name for AWS blog storage #6446


User avatar
0
carl.hallqvist created
  • ABP Framework version: v7.3.3
  • UI Type: Blazor WASM
  • Database System: EF Core SQL Server
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

I am trying to use AWS blog storage, but since it is S3 object storage, I think it shall be possible to use it on S3 storage in other cloud providers (in my case DigitalOcean).

So I am trying to follow this one: https://docs.abp.io/en/abp/latest/Blob-Storing-Aws

And I have the following properties when using S3cmd:

access_key = DOxxxxxxxxxxxxxx
secret_key = Qpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
check_ssl_certificate = True
check_ssl_hostname = True
host_base = fra1.digitaloceanspaces.com
host_bucket = %(bucket)s.fra1.digitaloceanspaces.com

I guess that it is the host_base that needs to be replaced from s3.amazonaws.com to digitaloceanspaces.com , but how can I do that? I can't find any properties that set that hostname.

Kind regards, Carl


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can try to override DefaultAmazonS3ClientFactory class to set additional properties, I'm not sure if it supports this. https://github.com/aws/aws-sdk-net

    https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/DefaultAmazonS3ClientFactory.cs#L30-L58

  • User Avatar
    0
    carl.hallqvist created

    Thanks,

    I think that will work out since it is possible to change host according to:

    using System;
    using Amazon;
    using Amazon.S3;
    using Amazon.S3.Model;
    
    string accessKey = Environment.GetEnvironmentVariable("SPACES_KEY");
    string secretKey = Environment.GetEnvironmentVariable("SPACES_SECRET");
    
    AmazonS3Config config = new AmazonS3Config();
    config.ServiceURL = "https://nyc3.digitaloceanspaces.com";
    
    AmazonS3Client s3Client = new AmazonS3Client(
            accessKey,
            secretKey,
            config
            );
    

    However, can you please show me how to override DefaultAmazonS3ClientFactory class? All I need is to override the public virtual async Task<AmazonS3Client> GetAmazonS3Client method, with two lines that explicit set the config.ServiceURL value from the example above.

    Kind regards, Carl

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    using System.Threading.Tasks;
    using Amazon.S3;
    using Volo.Abp.Caching;
    using Volo.Abp.DependencyInjection;
    using Volo.Abp.Security.Encryption;
    
    namespace Volo.Abp.BlobStoring.Aws;
    
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IAmazonS3ClientFactory), typeof(DefaultAmazonS3ClientFactory))]
    public class MyAmazonS3ClientFactory : DefaultAmazonS3ClientFactory
    {
        public MyAmazonS3ClientFactory(
            IDistributedCache<AwsTemporaryCredentialsCacheItem> cache,
            IStringEncryptionService stringEncryptionService)
            : base(cache, stringEncryptionService)
        {
        }
    
        public override Task<AmazonS3Client> GetAmazonS3Client(AwsBlobProviderConfiguration configuration)
        {
            // TODO: Add your custom logic here
            return base.GetAmazonS3Client(configuration);
        }
    }
    
  • User Avatar
    0
    carl.hallqvist created

    Thanks,

    Working perfectly.

    Kind regards, Carl

Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35