LitS3.S3Service.GetAuthorizedUrl C# (CSharp) Method

GetAuthorizedUrl() public method

Creates a pre-authorized URI valid for performing a GET on the given S3 object in the given bucket. This is useful for constructing a URL to hand over to a 3rd party (such as a web browser). The Uri will automatically expire after the time given. This method itself does not communicate with S3 and will return immediately.
You might expect this method to return a System.Uri instead of a string. It turns out there is a tricky issue with constructing Uri objects from these pre-authenticated url strings: The Uri.ToString() method will convert a properly-encoded "+" character back into a raw "+", which is interpreted by Amazon S3 as a space (standard URI conventions). So the signature will be misread if you were to take the Uri.ToString() and feed it to a browser. So instead, we'll give you a properly escaped URL string which will always work in a browser. If you want to, say, use it in a WebRequest instead, it turns out that WebRequest will leave it escaped properly and everything will work.
public GetAuthorizedUrl ( string bucketName, string key, System.DateTime expires ) : string
bucketName string
key string
expires System.DateTime
return string
        public string GetAuthorizedUrl(string bucketName, string key, DateTime expires)
        {
            string authorization = authorizer.AuthorizeQueryString(bucketName, key, expires);

            var uriString = new StringBuilder(GetUrl(bucketName, key))
                .Append("?AWSAccessKeyId=").Append(AccessKeyID)
                .Append("&Expires=").Append(expires.SecondsSinceEpoch())
                .Append("&Signature=").Append(Uri.EscapeDataString(authorization));

            return uriString.ToString();
        }