Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

support custom Amazon S3 endpoint URL #1039

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions Grand.Core/Configuration/GrandConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public GrandConfig()
/// </summary>
public string AmazonBucketName { get; set; }

/// <summary>
/// Custom Endpoint for third party S3 compatible service, example: https://sfo2.digitaloceanspaces.com
/// </summary>
public string AmazonRegionEndpoint { get; set; }

/// <summary>
/// Amazon Domain name for cloudfront distribution
/// </summary>
Expand Down
21 changes: 16 additions & 5 deletions Grand.Services/Media/AmazonPictureService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,24 @@ public partial class AmazonPictureService : PictureService
if (string.IsNullOrEmpty(_config.AmazonBucketName))
throw new ArgumentNullException("AmazonBucketName");

//Region guard
var regionEndpoint = RegionEndpoint.GetBySystemName(_config.AmazonRegion);
if (regionEndpoint.DisplayName == "Unknown")
throw new NullReferenceException("specified Region is invalid");
AmazonS3Config amazonS3Config = new AmazonS3Config();

if (string.IsNullOrEmpty(_config.AmazonRegionEndpoint))
{
//Region guard
var regionEndpoint = RegionEndpoint.GetBySystemName(_config.AmazonRegion);
if (regionEndpoint.DisplayName == "Unknown")
throw new NullReferenceException("specified Region is invalid");

amazonS3Config.RegionEndpoint = regionEndpoint;
}
else
{
amazonS3Config.ServiceURL = _config.AmazonRegionEndpoint;
}

//Client guard
_s3Client = new AmazonS3Client(_config.AmazonAwsAccessKeyId, _config.AmazonAwsSecretAccessKey, regionEndpoint);
_s3Client = new AmazonS3Client(_config.AmazonAwsAccessKeyId, _config.AmazonAwsSecretAccessKey, amazonS3Config);

//Bucket guard
_bucketName = _config.AmazonBucketName;
Expand Down
1 change: 1 addition & 0 deletions Grand.Web/App_Data/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"AmazonAwsSecretAccessKey": "",
"AmazonBucketName": "",
"AmazonRegion": "",
"AmazonRegionEndpoint": "", // third party S3 compatible service, example: https://sfo2.digitaloceanspaces.com
"AmazonDistributionDomainName": "", //Domain name for cloudfront distribution

///Enable the Publish/Subscribe messaging with redis to manage memory cache on every server
Expand Down