Merge pull request #97 from alanedwardes/amazon-s3-file-uploader

Fixed Amazon S3 URLs not being URL encoded.
This commit is contained in:
Jaex 2014-04-03 02:51:25 +03:00
commit 6a4cc81453

View file

@ -32,6 +32,7 @@ You should have received a copy of the GNU General Public License
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web;
namespace UploadersLib.FileUploaders
{
@ -103,6 +104,19 @@ private string CreateSignature(string secretKey, byte[] policyBytes)
return Convert.ToBase64String(signatureBytes);
}
private string GetObjectURL(string objectName)
{
var urlEncodedObjectName = Helpers.URLPathEncode(objectName);
if (S3Settings.UseCustomCNAME)
{
return string.Format("http://{0}/{1}", S3Settings.Bucket, urlEncodedObjectName);
}
else
{
return string.Format("{0}/{1}", GetEndpoint(), urlEncodedObjectName);
}
}
private Dictionary<string, string> GetParameters(string fileName, string objectKey)
{
var policyDocument = GetPolicyDocument(fileName);
@ -133,14 +147,7 @@ public override UploadResult Upload(Stream stream, string fileName)
if (uploadResult.IsSuccess)
{
if (S3Settings.UseCustomCNAME)
{
uploadResult.URL = string.Format("http://{0}/{1}", S3Settings.Bucket, objectKey);
}
else
{
uploadResult.URL = string.Format("{0}/{1}", GetEndpoint(), objectKey);
}
uploadResult.URL = GetObjectURL(objectKey);
}
return uploadResult;