[英]How do I add a Cache-Control HTTP header to images I upload to Amazon S3?
I think I'm probably just missing something in the docs here, but how do I specify that images I upload to S3 have a Cache-Control header when requested? 我想我可能只是缺少文档中的内容,但是如何指定上传到S3的图像在请求时有一个Cache-Control标头?
This answer seems to suggest you can do it by adding metadata, but the example isn't too clear. 这个答案似乎暗示你可以通过添加元数据来实现,但这个例子并不太清楚。 Can anyone point me to a code sample or some documentation of how I would do this in C# please? 任何人都可以指向我的代码示例或我将如何在C#中执行此操作的一些文档吗?
For those reading this question more recently, you can use the TransferUtilityUploadRequest 's Headers.CacheControl property (Note: At the time of writing the AWS documentation doesn't make it obvious that this is an available property). 对于那些最近阅读此问题的人,您可以使用TransferUtilityUploadRequest的Headers.CacheControl属性(注意:在撰写AWS文档时,并不明显这是一个可用的属性)。
eg 例如
// Make the upload request with the required cache and header parameters
var fileTransferUtilityRequest = new TransferUtilityUploadRequest
{
BucketName = BucketName,
FilePath = fileName,
StorageClass = S3StorageClass.Standard,
Key = keyName,
CannedACL = S3CannedACL.PublicRead,
ContentType = contentType,
};
fileTransferUtilityRequest.Headers.CacheControl = "max-age=604800";
var fileTransferUtility = new TransferUtility(...);
fileTransferUtility.Upload(fileTransferUtilityRequest);
Well, it turns out that this is possible using the REST API for S3, but not using the SOAP methods. 好吧,事实证明这可以使用REST API for S3,但不使用SOAP方法。 So the answer for me is just 'no' - unless we rewrite all our code to use the REST API. 所以我的答案就是'不' - 除非我们重写所有代码以使用REST API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.