Thursday, 15 March 2012

c# - Cloudfront Signed URLs not working with S3 content disposition filenames with spaces using .NET SDK -


I have a properly signed CloudFront URL with an S3 root and feedback-content-nature File To specify the name of the file, generate the string string parameter I generated using the signed URL. NET ADS SDK AmazonCloudFrontUrlSigner.GetCannedSignedURL method works correctly when the content is in the privacy filename There is no free space . However, if the file name contains spaces, I have been denied access. Therefore, as the code below will generate some URL which is deprived of access.

  var contentDisposition = HttpUtility.UrlEncode ("attachment; file name = my file.txt"); Var key = "example.txt? Response-content-nature =" + content dispection; Back to AmazonCloudFrontUrlSigner.GetCannedSignedURL (AmazonCloudFrontUrlSigner.Protocol.https, "myBucket", CloudFriendPrivate, Key, CloudFrontInvestIID, End DateTime);  

This is clearly something to do with url encoding.

I have read through all the information about docs I have read. I've also tried a number of combinations like UrlEncode , just encoding the file name part and place it with the encoded version after encoding not even the signed URL generated. All of them are either denied access or there is an error that does not match the signature URL.

HttpUtility.UrlEncode is acceptable according to the system standards which as the encoding of the spaces, however, for some reason I do not understand, it produces problems with the signed URL and content nature. Other encoding of space works correctly as % 20 , so after encoding, replace + with % 20 . The working version is:

  var contentDisposition = HttpUtility.UrlEncode ("attachment; file name = my file.txt"); ContentDisposition = contentDisposition.Replace ("+", "% 20"); Var key = "example.txt? Response-content-nature =" + content dispection; Back to AmazonCloudFrontUrlSigner.GetCannedSignedURL (AmazonCloudFrontUrlSigner.Protocol.https, "myBucket", CloudFriendPrivate, Key, CloudFrontInvestIID, End DateTime);  

No comments:

Post a Comment