mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-04 12:14:45 +13:00
Merge pull request #97 from alanedwardes/amazon-s3-file-uploader
Fixed Amazon S3 URLs not being URL encoded.
This commit is contained in:
commit
6a4cc81453
1 changed files with 15 additions and 8 deletions
|
@ -32,6 +32,7 @@ You should have received a copy of the GNU General Public License
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
namespace UploadersLib.FileUploaders
|
namespace UploadersLib.FileUploaders
|
||||||
{
|
{
|
||||||
|
@ -103,6 +104,19 @@ private string CreateSignature(string secretKey, byte[] policyBytes)
|
||||||
return Convert.ToBase64String(signatureBytes);
|
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)
|
private Dictionary<string, string> GetParameters(string fileName, string objectKey)
|
||||||
{
|
{
|
||||||
var policyDocument = GetPolicyDocument(fileName);
|
var policyDocument = GetPolicyDocument(fileName);
|
||||||
|
@ -133,14 +147,7 @@ public override UploadResult Upload(Stream stream, string fileName)
|
||||||
|
|
||||||
if (uploadResult.IsSuccess)
|
if (uploadResult.IsSuccess)
|
||||||
{
|
{
|
||||||
if (S3Settings.UseCustomCNAME)
|
uploadResult.URL = GetObjectURL(objectKey);
|
||||||
{
|
|
||||||
uploadResult.URL = string.Format("http://{0}/{1}", S3Settings.Bucket, objectKey);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
uploadResult.URL = string.Format("{0}/{1}", GetEndpoint(), objectKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return uploadResult;
|
return uploadResult;
|
||||||
|
|
Loading…
Reference in a new issue