Question

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?

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?

Was it helpful?

Solution 2

Well, it turns out that this is possible using the REST API for S3, but not using the SOAP methods. So the answer for me is just 'no' - unless we rewrite all our code to use the REST API.

See this AWS Support Forum post.

OTHER TIPS

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).

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top