mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 09:17:36 +13:00
Merge pull request #6257 from Jefemy/develop
Change url prefix addition in S3 uploader
This commit is contained in:
commit
1a23637e5e
2 changed files with 10 additions and 4 deletions
|
@ -421,6 +421,11 @@ public static bool HasPrefix(string url)
|
|||
return URLPrefixes.Any(x => url.StartsWith(x, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
public static string GetPrefix(string url)
|
||||
{
|
||||
return URLPrefixes.Find(x => url.StartsWith(x, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
public static string FixPrefix(string url, string prefix = "http://")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(url) && !HasPrefix(url))
|
||||
|
|
|
@ -125,6 +125,7 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
isPathStyleRequest = true;
|
||||
}
|
||||
|
||||
string scheme = URLHelpers.GetPrefix(Settings.Endpoint);
|
||||
string endpoint = URLHelpers.RemovePrefixes(Settings.Endpoint);
|
||||
string host = isPathStyleRequest ? endpoint : $"{Settings.Bucket}.{endpoint}";
|
||||
string algorithm = "AWS4-HMAC-SHA256";
|
||||
|
@ -205,8 +206,8 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
headers.Remove("Host");
|
||||
headers.Remove("Content-Type");
|
||||
|
||||
string url = URLHelpers.CombineURL(host, canonicalURI);
|
||||
url = URLHelpers.ForcePrefix(url, "https://");
|
||||
string url = URLHelpers.CombineURL(scheme + host, canonicalURI);
|
||||
url = URLHelpers.FixPrefix(url, "https://");
|
||||
|
||||
SendRequest(HttpMethod.PUT, url, stream, contentType, null, headers);
|
||||
|
||||
|
|
Loading…
Reference in a new issue