Merge pull request #2460 from hclewk/master

Fix S3 Uploads with random paths
This commit is contained in:
Jaex 2017-04-24 15:56:43 +03:00 committed by GitHub
commit 1901a73eb5
2 changed files with 9 additions and 8 deletions

View file

@ -125,8 +125,10 @@ public override UploadResult Upload(Stream stream, string fileName)
args.Add("X-Amz-SignedHeaders", signedHeaders);
string uploadPath = GetUploadPath(fileName);
if (forcePathStyle) uploadPath = URLHelpers.CombineURL(Settings.Bucket, uploadPath);
string canonicalURI = URLHelpers.AddSlash(uploadPath, SlashType.Prefix);
string canonicalURI = uploadPath;
if (forcePathStyle) canonicalURI = URLHelpers.CombineURL(Settings.Bucket, canonicalURI);
canonicalURI = URLHelpers.AddSlash(canonicalURI, SlashType.Prefix);
canonicalURI = URLHelpers.URLPathEncode(canonicalURI);
string canonicalQueryString = URLHelpers.CreateQuery(args);
@ -176,7 +178,7 @@ public override UploadResult Upload(Stream stream, string fileName)
return new UploadResult
{
IsSuccess = true,
URL = GenerateURL(fileName)
URL = GenerateURL(uploadPath)
};
}
@ -221,18 +223,16 @@ private string GetRegion()
return serviceAndRegion.Substring(separatorIndex + 1);
}
private string GetUploadPath(string fileName)
public string GetUploadPath(string fileName)
{
string path = NameParser.Parse(NameParserType.FolderPath, Settings.ObjectPrefix.Trim('/'));
return URLHelpers.CombineURL(path, fileName);
}
public string GenerateURL(string fileName)
public string GenerateURL(string uploadPath)
{
if (!string.IsNullOrEmpty(Settings.Endpoint) && !string.IsNullOrEmpty(Settings.Bucket))
{
string uploadPath = GetUploadPath(fileName);
string url;
if (Settings.UseCustomCNAME && !string.IsNullOrEmpty(Settings.CustomDomain))

View file

@ -492,7 +492,8 @@ public void DropboxAuthComplete(string code)
private void UpdateAmazonS3Status()
{
lblAmazonS3PathPreview.Text = new AmazonS3(Config.AmazonS3Settings).GenerateURL("Example.png");
var s3 = new AmazonS3(Config.AmazonS3Settings);
lblAmazonS3PathPreview.Text = s3.GenerateURL(s3.GetUploadPath("Example.png"));
}
#endregion Amazon S3