我打算在公共桶中使用私有对象,从而限制对对象的访问,而不是桶中的其他对象.我想设置CloudFront以使用签名URL提供内容.现在在AWS S3文档中,我看到两个不同的术语,一个是用于访问私有对象的预签名URL,另一个是签名URL,需要下载私钥等并执行更多操作.
预签名URL和签名URL有什么区别?我可以
PreSigned在CloudFront中使用URL吗?
C#库有方法GetPreSignedURL,是否自动下载私钥等并进行签名或此GetPreSignedURL方法与S3 URL签名不同,需要设置私钥然后签署URL?
我正在使用Amazon .NET SDK生成预先签名的URL,如下所示:
public System.Web.Mvc.ActionResult AsActionResult(string contentType, string contentDisposition)
{
ResponseHeaderOverrides headerOverrides = new ResponseHeaderOverrides();
headerOverrides.ContentType = contentType;
if (!string.IsNullOrWhiteSpace(contentDisposition))
{
headerOverrides.ContentDisposition = contentDisposition;
}
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest()
.WithBucketName(bucketName)
.WithKey(objectKey)
.WithProtocol(Protocol.HTTPS)
.WithExpires(DateTime.Now.AddMinutes(6))
.WithResponseHeaderOverrides(headerOverrides);
string url = S3Client.GetPreSignedURL(request);
return new RedirectResult(url, permanent: false);
}
Run Code Online (Sandbox Code Playgroud)
这非常有效,除非我的中contentType包含一个+.当我尝试获取SVG文件(例如,获取内容类型)时会发生这种情况image/svg+xml.在这种情况下,S3会抛出SignatureDoesNotMatch错误.
错误消息显示StringToSign如下:
GET 1234567890 /blah/blabh/blah.svg?response-content-disposition=filename="blah.svg"&response-content-type=image/svg xml
Run Code Online (Sandbox Code Playgroud)
请注意,response-content-type中有一个空格,现在它image/svg xml代替的是image/svg+xml.在我看来,这就是导致问题的原因,但是解决这个问题的正确方法是什么?
我应该编码我的内容类型吗?用引号或其他东西括起来?文档没有说明这一点.