fixed #2440 #2451: If Amazon S3 bucket name contains dot then use path style request url

This commit is contained in:
Jaex 2017-04-23 16:37:52 +03:00
parent d42acd468a
commit 887d603e4b

View file

@ -91,8 +91,15 @@ public AmazonS3(AmazonS3Settings settings)
public override UploadResult Upload(Stream stream, string fileName)
{
bool forcePathStyle = Settings.UsePathStyle;
if (!forcePathStyle && Settings.Bucket.Contains("."))
{
forcePathStyle = true;
}
string endpoint = URLHelpers.RemovePrefixes(Settings.Endpoint);
string host = Settings.UsePathStyle ? endpoint : $"{Settings.Bucket}.{endpoint}";
string host = forcePathStyle ? endpoint : $"{Settings.Bucket}.{endpoint}";
string algorithm = "AWS4-HMAC-SHA256";
string credentialDate = DateTime.UtcNow.ToString("yyyyMMdd", CultureInfo.InvariantCulture);
string region = GetRegion();
@ -118,7 +125,7 @@ public override UploadResult Upload(Stream stream, string fileName)
args.Add("X-Amz-SignedHeaders", signedHeaders);
string uploadPath = GetUploadPath(fileName);
if (Settings.UsePathStyle) uploadPath = URLHelpers.CombineURL(Settings.Bucket, uploadPath);
if (forcePathStyle) uploadPath = URLHelpers.CombineURL(Settings.Bucket, uploadPath);
string canonicalURI = URLHelpers.AddSlash(uploadPath, SlashType.Prefix);
canonicalURI = URLHelpers.URLPathEncode(canonicalURI);