Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Update [workaround]</h2> <p>I've meanwhile resolved the contradicting test results of mine, which stem from respectively unsystematic testing and URL manipulations. The following <strong>workaround</strong> does the trick for me (i.e. tested and reproducible), simply starting from your solution:</p> <pre><code>string bucketName = "foo.example.com"; // [...] GetPreSignedUrlRequest request = new GetPreSignedUrlRequest() .WithBucketName(bucketName) .WithKey(key) .WithExpires(DateTime.Now.AddMinutes(32)) .WithProtocol(Protocol.HTTP); </code></pre> <p>Now this yields the erroneous URL with a duplicate domain name, i.e. <code>http://foo.example.com.foo.example.com/myfile.txt?[...]</code></p> <p>The duplicate can simply be removed though, e.g.:</p> <pre><code>string url = s3Client.GetPreSignedURL(request); // KLUDGE: remove duplicate domain name. url = url.Replace(bucketName + "." + bucketName, bucketName); </code></pre> <p>This yields a proper working pre-signed URL for me (i.e. <code>http://foo.example.com/myfile.txt?[...]</code>) by working around the encountered limitation regarding the desired approach outlined below.</p> <h3>Justification</h3> <p>Manipulating the generated URL like so seems odd, but this not having an effect on the query string authentication is in line with how these signatures are created, see <a href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationQueryStringAuth" rel="nofollow noreferrer">Query String Request Authentication Alternative</a>, where you'll find the <em>pseudo-grammar that illustrates the query string request authentication method</em>:</p> <pre><code>StringToSign = HTTP-VERB + "\n" + Content-MD5 + "\n" + Content-Type + "\n" + Expires + "\n" + CanonicalizedAmzHeaders + CanonicalizedResource; </code></pre> <p>That is, the domain name isn't used for the signature creation at all, rather only information regarding the resource itself; section <em>Example Query String Request Authentication</em> right below the referenced pseudo-grammar fragment illustrates this with an actual resource.</p> <h3>Assessment</h3> <p>I don't know whether there is still a misunderstanding on our part or whether this might just be a bug in the <a href="http://aws.amazon.com/sdkfornet/" rel="nofollow noreferrer">AWS SDK for .NET</a>, see e.g. <a href="https://stackoverflow.com/questions/9051650/why-is-my-s3-pre-signed-request-invalid-when-i-set-a-response-header-override-th">Why is my S3 pre-signed request invalid when I set a response header override that contains a “+”?</a> for a related bug resolved via a similar workaround as well, which has meanwhile been fixed though; accordingly, this should likely be escalated to the AWS forums and/or support channels to get an appropriate answer or solution.</p> <p>Good luck!</p> <hr> <h2>Desired answer [dysfunctional]</h2> <p>The S3 CNAME handling implies the bucket name already, so all you need to do is removing your bucket name from <code>GetPreSignedUrlRequest</code>, i.e. it should look like so:</p> <pre><code>GetPreSignedUrlRequest request = new GetPreSignedUrlRequest() .WithKey(key) .WithExpires(DateTime.Now.AddMinutes(5)) .WithProtocol(Protocol.HTTP); </code></pre> <p><strike>I've tested this with a bucket of mine and it works as expected like so.</strike></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload